kedaOJ#P0891. 四次方数
题目
P0891. 四次方数
思路
简单的动态规划
代码
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int m;
int v[19] = {1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000, 14641, 20736, 28561, 38416, 50625, 65536, 83521};
int dp[100001];
int main() {
scanf("%d", &m);
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for (int i = 0; i <= 17; i++)
for (int j = v[i]; j <= m; j++)
dp[j] = min(dp[j], dp[j - v[i]] + 1);
printf("%d", dp[m]);
return 0;
}
这是mcr130102的博客,转载请注明出处