<strong>这道题是水题,题目告诉我们有5种类型的硬币,面值为1, 5, 10, 25, 50.给我们一个钱数, 让我们求用这五种面值有几种方法可以表示这个钱数。这里用dp[j]来表示当面值为j时, 有几种可能来表示j.用dp[5]举例, 在程序中,dp[5] = dp[4] + dp[0]. dp[4] 是因为他可以加一元到5, 而dp[0]是因为他可以加5元到5. 这里要注意的是,dp[0] = 1.</strong>
<strong>
</strong>
</pre><pre name="code" class="cpp">#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define mem(a) memset(a, 0, sizeof(a))
using namespace std;
int type[5] = {1, 5, 10, 25, 50}, dp[8000];
int main(int argc, char *argv[])
{
int num, i, j, k;
while(scanf("%d",&num) != EOF)
{
mem(dp);
dp[0] = 1;
for(i = 0;i < 5;i++)
{
for(j = 1;j <= num;j++)
{
if((j - type[i]) >= 0)
dp[j] += dp[j - type[i]];
}
}
printf("%d\n", dp[num]);
}
return 0;
}