您的位置:首页 > 其它

HDU1284:钱币兑换问题(完全背包)

2013-06-07 19:00 309 查看
Problem Description
在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。


Input
每行只有一个正整数N,N小于32768。


Output
对应每个输入,输出兑换方法数。


Sample Input
2934
12553




Sample Output
718831
13137761






也是一道之前暴力过的题

现在用完全被曝再过一次

与1248题相似

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int dp[32768];

int main()
{
    int n;
    int val[3] = {1,2,3};
    while(~scanf("%d",&n))
    {
        int i,j;
        memset(dp,0,sizeof(dp));
        dp[0] = 1;
        for(i = 0;i<3;i++)
        {
            for(j = val[i];j<=n;j++)
            {
                dp[j]+=dp[j-val[i]];
            }
        }
        printf("%d\n",dp
);
    }

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