usaco: Money Systems
来源:互联网 发布:js获取页面加载的时间 编辑:程序博客网 时间:2024/05/17 04:05
res(i, j)表示用前 j 种组合出 i 。那么:res(i, j) = res(i - coin[i], j - 1) + res(i, j - 1),即结果有两种情况:取第 j 种钱和不取第 j 种钱。
/*ID: LANG: C++TASK: money*/#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <vector>#define IN "money.in"#define OUT "money.out"#define MaxV 30#define MaxN 10005using namespace std;int v, n;int coin[MaxV];long long res[MaxN][MaxV]; //res(i, j): 用前j种钱组合出ivoid solve(){ memset(res, 0, sizeof(0)); int tmp = coin[0]; while(tmp <= n) { res[tmp][1] = 1; tmp += coin[0]; } for(int i = 1; i <= v; i++) res[0][i] = 1; for(int i = 2; i <= v; i++) { for(int j = 1; j <= n; j++) { if(j - coin[i-1] >= 0) res[j][i] = res[j-coin[i-1]][i] + res[j][i-1]; else res[j][i] = res[j][i-1]; } }}int main(){ freopen(IN, "rb", stdin); freopen(OUT, "wb", stdout); while(scanf("%d%d", &v, &n) != EOF) { for(int i = 0; i < v; i++) scanf("%d", &coin[i]); solve(); printf("%lld\n", res[n][v]); } fclose(stdin); fclose(stdout); return 0;}
- USACO 2.3 Money Systems (money)
- usaco: Money Systems
- usaco Money Systems
- USACO-Money Systems
- usaco Money Systems
- USACO-Money Systems
- 【动态规划】【USACO】Money Systems
- USACO :Money Systems解题报告
- USACO 2.3.4 Money Systems
- USACO--2.3Money Systems+dp
- USACO 2.3.4 Money Systems
- USACO 2.3 Money Systems 题解
- USACO-Section2.3 Money Systems
- USACO / Money Systems货币系统(DP)
- USACO section 2.3 Money Systems(dp)
- USACO section2.3 Money Systems题解&代码
- USACO 2.3 Money Systems (DP 动态规划)
- USACO-Section 2.3 Money Systems(DP)
- 第八周实验报告2
- [POJ]1517 u Calculate e
- 4G探路
- 第八周任务2:实现Time类中的运算符重载
- 可以在Service中使用handler么?
- usaco: Money Systems
- JavaScript访问控制外部CSS并判断浏览器版本
- <Revit二次开发> Create Doors in Wall
- getHibernateTemplate().save不写入数据库的解决
- 九度OJ题目1420:Jobdu MM分水果
- WinPhone7使用调用WCF传递对象
- 听说爱
- 第八周实验报告3
- android布局中的一些记录