Fork me on GitHub

hdu 1284 钱币兑换问题 完全背包

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284

递推公式:dp[i] = sum(dp[i], dp[i-C])

/*
钱币兑换问题

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6325    Accepted Submission(s): 3662


Problem Description
在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
 

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

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

Sample Input
2934
12553
 

Sample Output
718831
13137761
 

Author
SmallBeer(CML)
 

Source
杭电ACM集训队训练赛(VII)
*/
#include <cstdio>
#include <cstring>
int n;
const int maxn = 32768 + 10;
int value[4] = {0, 1, 2, 3};
int dp[maxn];
void Pack()
{
    dp[0] = 1;
    for(int i = 1; i <= 3; i++)
        for(int j = value[i]; j < maxn; j++){
            dp[j] += dp[j - value[i]];
        }
}
int main()
{
    Pack();
    while(~scanf("%d", &n)){
        printf("%d\n", dp[n]);
    }
    return 0;
}

 

posted @ 2015-02-16 18:01  I'm coding  阅读(668)  评论(0编辑  收藏  举报