题目:http://acm.hdu.edu.cn/showproblem.php?pid=1284
题意:
Problem Description
在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
Input
每行只有一个正整数N,N小于32768。
Output
对应每个输入,输出兑换方法数。
Sample Input
2934
12553
Sample Output
718831
13137761
思路:完全背包求方案数。。。
总结:突然发现自己连背包都做不好了,好心酸,于是来了一套背包题,残疾人康复指南之重学背包系列。。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 50010;
int dp[N];
int main()
{
int n;
int v[10], w[10];
v[1] = w[1] = 1,v[2] = w[2] = 2, v[3] = w[3] = 3;
memset(dp, 0, sizeof dp);
dp[0] = 1;
for(int i = 1; i <= 3; i++)
for(int j = w[i]; j <= 32768; j++)
dp[j] += dp[j-w[i]];
while(~ scanf("%d", &n))
printf("%d\n", dp[n]);
return 0;
}