UVa:357 Let Me Count The Ways
来源:互联网 发布:富盈网络水军 编辑:程序博客网 时间:2024/05/16 18:28
状态转移方程是dp[i][j]=dp[i-1][j]+dp[i][j-m[i]];
d[i][j]是使用前i种金币可以组合成j钱的种数。
它包括两种情况,一种是不使用第i种金币的时候,另一种是使用第i种金币的时候。
可以直接用一维数组,前提是不打印最优解。
#include <cstdio>#include <iostream>#include <cstdlib>using namespace std;int main(){ int m[]={0,1,5,10,25,50}; long long dp[30005]={0}; dp[0]=1; for(int i=1;i<6;++i) for(int j=0;j<=30000;++j) if(j>=m[i]) dp[j]=dp[j]+dp[j-m[i]]; int n; while(scanf("%d",&n)!=EOF) { if(dp[n]==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],n); } return 0;}
- uva 357 Let Me Count The Ways
- uva 357 - Let Me Count The Ways
- UVA 357 Let Me Count The Ways
- UVA 357 Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- uva 357 let me count the ways
- UVa 357 - Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- UVA-357-Let Me Count The Ways
- UVA 357 Let Me Count The Ways
- UVa:357 Let Me Count The Ways
- UVa 357: Let Me Count The Ways
- UVA - 357 Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- uva 357 Let Me Count The Ways
- uva 357 - Let Me Count The Ways
- uva 357 Let Me Count The Ways
- sdjzu 1117
- Delphi & C++ Builder 本地化顯示中文技巧
- uva 704
- XMPP聊天客户端环境搭建
- 有中国电信手机一定要看。CTWAP和CTNET是什么意思?有什么区别?
- UVa:357 Let Me Count The Ways
- Ubuntu右键菜单添加新建OpenOffice文件
- rild 源码分析
- hdu 1002
- .Net MVC4 使用心得(五)细节问题Url.Action和Html.ActionLink
- 简单介绍Java EE容器
- VC++之屏幕抓取
- 第一篇文章
- xml--通过jdom解析及生产XML