UVA 357 Let Me Count The Ways

水题,不解释:

代码如下:

#include<stdio.h>
#include<string.h>
#define MAXN 30000 + 100
long long f[MAXN];
int chang[6] = {0,1,5,10,25,50};
int n;
void solve()
{
memset(f,0,sizeof(f));
f[0] = 1;
int max = 30000;
for(int i = 1; i <= 5; i ++)
for(int j = chang[i]; j <= max; j ++)
f[j] += f[j - chang[i]];
}
void input()
{
solve();
while(scanf("%d",&n) == 1)
if(f[n] == 1) printf("There is only 1 way to produce %d cents change.\n",n);
else printf("There are %lld ways to produce %d cents change.\n",f[n],n);
}
int main()
{
input();
return 0;
}



原文地址:https://www.cnblogs.com/yuzhaoxin/p/2397047.html