`
836811384
  • 浏览: 545616 次
文章分类
社区版块
存档分类
最新评论

hdu1284经典钱币兑换问题

 
阅读更多

钱币兑换问题。

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

完全背包。

这种是求背包问题最多的组合方案

参考了一些资料 http://blog.csdn.net/wumuzi520/article/details/7021210




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

int dp[32768];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int i,j;
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        for(i=1;i<=3;i++)
        {
            for(j=i;j<=n;j++)
            {
				if (j>=i)
                dp[j]=dp[j]+dp[j-i];
            }
        }
        cout<<dp[n]<<endl;
    }
    return 0;
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics