您的位置:首页 > 其它

UVA - 357 Let Me Count The Ways

2013-09-10 19:26 363 查看
题意:还是凑钱问题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 30005;

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

int main(){
    memset(dp,0,sizeof(dp));
    dp[0] = 1;
    for (int i = 0; i < 5; i++)
        for (int j = money[i]; j < MAXN; j++)
            dp[j] += dp[j - money[i]];
    int n;
    while (scanf("%d",&n) != EOF){
        if (dp
 == 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",dp
,n);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: