标签:
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int main() { int dp[60010]; int n; while(~scanf("%d",&n)){ memset(dp,0,sizeof(dp)); for(int i = 1; i <= n ;i++){ dp[i] = dp[i-1] + 1; for(int j = 1; j <= sqrt((double)n+0.5); j++) if(j*j <= i) dp[i] = min(dp[i],dp[i-j*j] + 1); } printf("%d\n",dp[n]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4488761.html