POJ 1742 Coins
来源:互联网 发布:pc端护眼软件 编辑:程序博客网 时间:2024/04/30 18:06
/*2016年8月2日19:50:12 有 n 种硬币,每种硬币有 c 个,问这 n 种硬币能组成 1-m 的多少个价值。直接用多重背包会T 多重背包另一种做法 布尔值 dp[i] 表示能否组成i价值 cnt[i] 表示组成i价值 要使用多少个 当前的硬币 详见代码 */#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <cmath>#include <stack>#include <map>#include <set>#define pi acos(-1)#define LL long long#define INF 0x3f3f3f3fusing namespace std;const int maxn = 1e5 + 5;bool dp[maxn];int A[105], C[105];int cnt[maxn];int n, m;int main(void){//freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin); int i, j, ans; while (~scanf("%d %d", &n, &m) && (n||m)) { for (i = 1; i <= n; i++) scanf("%d", &A[i]); for (i = 1; i <= n; i++) scanf("%d", &C[i]); memset(dp, false, sizeof(dp)); dp[0] = true; ans = 0; for (i = 1; i <= n; i++){ memset(cnt, 0, sizeof(cnt)); for (j = A[i]; j <= m; j++){ if (!dp[j] && dp[j - A[i]] && cnt[j - A[i]] < C[i]){ dp[j] = true; cnt[j] = cnt[j - A[i]] + 1; ans++; } } } cout << ans << endl; } return 0;}
0 0
- poj 1742 Coins
- POJ 1742 Coins
- POJ 1742 Coins
- poj 1742 Coins
- poj 1742 Coins
- POJ 1742 coins
- POJ 1742 Coins
- poj 1742 Coins
- POJ 1742 Coins
- poj 1742 coins
- POJ 1742 Coins (DP)
- poj 1742 Coins
- poj 1742 Coins(dp)
- POJ 1742 Coins
- poj 1742 Coins
- 【POJ 1742】Coins
- poj 1742 Coins
- POJ 1742 Coins
- java.sql.SQLException: ORA-02290: 违反检查约束条件 (GZSYJ_MH.SYS_C0019581)
- HDU 4514 湫湫系列故事——设计风景线(连通分支,树的直径,并查集,环的判断)
- POJ 3616 Milking Time
- 高性能 CSS3 动画
- buddy内存分配算法浅析
- POJ 1742 Coins
- Android 面试总结
- HDU 1281 棋盘游戏-二分匹配
- Java正则表达式Matcher.group(int group)相关类解析
- POJ3181 Dollar Dayz
- 二叉树
- POJ 2253 Frogger
- POJ2993&&POJ2996
- 历史上的今天