标签:问题 span i++ == sdn content round 范围 ref
题目链接:http://acm.hdu.edu.cn/showproblem.php?
思路:仅仅有3个硬币,范围是32768。能够一个一个枚举硬币。假设仅仅放价值为1的硬币,从d[1]递推到d[n]。假设再加上价值为2的硬币,那么就从d[2]递推到d[n];在加上价值为3的硬币。就从d[3]递推到d[n].递推公式是d[j] = d[j] + d[j-i]; d[j]表示j有几种仅仅用1,2, 3这三个数字的拆分方法,i 就是硬币的价值
code:
#include<stdio.h>
#include<math.h>
#include<string.h>
int dp[32800];
int main()
{
int n,i,j;
memset(dp,0,sizeof(dp));
dp[0]=1;
for(i=1;i<=3;i++)
{
for(j=i;j<=32770;j++)
{
dp[j]+=dp[j-i];
}
}
while(scanf("%d",&n)==1)
{
printf("%d\n",dp[n]);
}
return 0;
}
标签:问题 span i++ == sdn content round 范围 ref
原文地址:http://www.cnblogs.com/wgwyanfs/p/6805135.html