|
|
back to boardHere is DP solution. If you know the Lagrange's proof about the theory, please contact me. megatronbiao@gmail.com DP is easy. I want to know the easiest solution to the problem. Please contact me. megatronbiao@gmail.com Thanks. Sorry for my English. #include <iostream> #include <cmath> using namespace std; int data[60001]; int main() { int n; cin>>n; data[1]=1; data[2]=2; for (int i=3;i<=n;++i) { int min=data[i-1]+1; for (int j=2;j<=245;++j) { if (i>=j*j) { if (min>data[i-j*j]+1) min=data[i-j*j]+1; } else break; } data[i]=min; } cout<<data[n]; return 0; } |
|
|