您的位置:首页 > 其它

uva_357 Let Me Count The Ways

2012-10-30 18:15 435 查看
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define COIN    5
#define MAXN    30000+10

unsigned long long dp[MAXN];
int coin[] = {1, 5, 10, 25, 50};

void complete_knapsack(void)
{
memset(dp, 0, sizeof(dp)); dp[0] = 1;
for(int i = 0; i < COIN; i ++) {
for(int j = 1; j < MAXN; j ++) {
if( j < coin[i] ) {
continue;
}
dp[j] += dp[j-coin[i]];
}
}
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
int n;
complete_knapsack();
while( ~scanf("%d", &n) ) {
if( 1 == dp
) {
printf("There is only 1 way to produce %d cents change.\n", n);
}
else {
printf("There are %llu ways to produce %d cents change.\n", dp
, n);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: