水题,不解释:

代码如下:

#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;
}



相关文章:

  • 2021-11-06
  • 2021-10-15
  • 2022-01-09
  • 2021-04-04
  • 2021-10-27
  • 2021-06-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-09-23
  • 2022-12-23
  • 2021-07-27
相关资源
相似解决方案