UVA 357 Let Me Count The Ways

题目大意:原理同UVA674,求凑钱种数

解题策略:DP,状态转移方程同674,大小开到30000+,注意数组溢出

 

/*
   UVA 357 Let Me Count The Ways
   AC by J.Dark
   ON 2013/3/12
   Time 0.028s
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 30005;
unsigned long long int dp[maxn];
int coin[5]={1, 5, 10, 25, 50};
/
void solve(){
     memset(dp, 0, sizeof(dp));
     dp[0] = 1;
     for(int i=0; i<5; i++){
        //j=coin[i],这里是wa点 
        for(int j=coin[i]; j<=maxn; j++){
           dp[j] += dp[j-coin[i]];
        }
     }
}
int main(){
    int N;
    solve();
    while(cin >> N)
    {
       //cout << N << endl;
       if(dp[N] != 1){
           printf("There are %llu ways to produce ", dp[N]);
           //printf("There are %d ways to produce %d cents change.\n",  dp[N], N);
           printf("%d cents change.\n", N);}
       else
           printf("There is only 1 way to produce %d cents change.\n", N);
    }
    //system("pause");
    return 0;
}


 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值