首页 > 学院 > 开发设计 > 正文

UVA.357 Let Me Count The Ways (DP 完全背包)

2019-11-08 19:45:33
字体:
来源:转载
供稿:网友

UVA.357 Let Me Count The Ways (DP 完全背包)

题意分析

与UVA.UVA.674 Coin Change是一模一样的题。需要注意的是,此题的数据量较大,dp数组需要使用long long 类型;另外输出方案为1个和多个的时候,语句是不同的。

代码总览

/* Title:UVA.357 Author:pengwill Date:2017-2-16*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define nmax 30005#define ll long longusing namespace std;ll dp[nmax];int m[5] = {1,5,10,25,50};int main(){ dp[0] = 1; for(int i = 0; i<5 ;++i){ for(int j= 0;j+m[i]<nmax;++j){ dp[j+m[i]] += dp[j]; } } int n; while(scanf("%d",&n)!= EOF){ if(dp[n] == 1) PRintf("There is only %lld way to produce %d cents change./n",dp[n],n); else printf("There are %lld ways to produce %d cents change./n",dp[n],n); } return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表