提交时间:2023-12-09 09:45:29

运行 ID: 114807

#include<bits/stdc++.h> using namespace std; vector<int> f(1010,0x3f3f3f3f); int n; int main() { cin>>n; int m = sqrt(n); f[0] = 0; for(int i = 1;i <= m; i++){ for(int j = i * i ;j <= n; j++){ f[j] = min(f[j] , f[j - i * i] + 1); } } cout<<f[n]<<endl; return 0; }