您的位置:首页 > 其它

UVa 357 - Let Me Count The Ways

2013-06-13 11:17 471 查看
/*
注意要用long long
*/
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
const int MAXN = 30005;
int coins[] = {1, 5, 10, 25, 50};
int type = sizeof(coins) / sizeof(coins[0]);
long long d[MAXN];

void dp()
{
d[0] = 1;
for(int i=0; i<type; i++) {
for(int j=1; j<=30000; j++) if(j >= coins[i]){
d[j] += d[j-coins[i]];
}
}
}

int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
dp();
int n;
while(scanf("%d", &n)==1) {
if(d
== 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", d
, n);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: