HDU 1284 钱币兑换问题 (完全背包)

钱币兑换问题

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


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

 

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

 

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

 

Sample Input
2934 12553
 

 

Sample Output
718831 13137761
 

 

Author
SmallBeer(CML)
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1171 2159 2191 1203 1028
 
还是比较好的这一题,完全背包的思路 但是不完全一样。
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 32788
#define M 12

int n;
int f[N];
int w[4]={0,1,2,3};
int main()
{
    while(~scanf("%d",&n))
    {
        memset(f,0,sizeof(f));
        f[0]=1;
        for(int i=1;i<=3;i++)
            for(int j=w[i];j<=n;j++)
        {
            f[j]=f[j]+f[j-w[i]];
        }
        cout<<f[n]<<endl;
    }
    return 0;
}

 

posted @ 2015-08-21 22:11  wmxl  阅读(198)  评论(0编辑  收藏  举报