您的位置:首页 > 其它

ural 1073. Square Country

2014-03-30 19:11 369 查看
http://acm.timus.ru/problem.aspx?space=1&num=1073

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 70000
using namespace std;
const int inf=99999999;
int dp[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
dp[i]=inf;
}
dp[1]=1;
for(int i=2; i<=n; i++)
{
int k=(int)sqrt((double)i);
for(int j=0; j<=k; j++)
{
dp[i]=min(dp[i],dp[i-j*j]+1);
}
}
printf("%d\n",dp
);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: