钱币兑换问题。
题目 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;
}
扫描二维码关注公众号,回复:
12419837 查看本文章
