poj 1742 Coins (背包)
来源:互联网 发布:数据库字段注释 编辑:程序博客网 时间:2024/04/30 19:56
这道题直接多重背包算的话会超时,但是按完全背包dp但在计算过程中用一个标记数组标记一下加了几次该coin 得到该值。这样可以使时间复杂度降低很多。。。
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;const int N = 111;const int M = 111111;int a[N], c[N];int dp[M];int mark[M];int main(){ int n, m; while(scanf("%d%d", &n, &m), n + m) { for(int i = 0; i < n; i ++) scanf("%d", &a[i]); for(int j = 0; j < n; j ++) scanf("%d", &c[j]); memset(dp, 0, sizeof(dp)); dp[0] = 1; for(int i = 0; i < n; i ++) { for(int j = 0; j <= m; j ++) mark[j] = 0;//标记数组,记得每次都置零 for(int j = 0; j <= m - a[i]; j ++) { if(dp[j] && !dp[j + a[i]] && mark[j] < c[i]) { dp[j + a[i]] = 1; mark[j + a[i]] = mark[j] + 1; } } } int ans = 0; for(int i = 1; i <= m; i ++) if(dp[i]) ans ++; printf("%d\n", ans); }}
- 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(多重背包)
- POJ 1742 Coins (多重背包)
- poj-1742 Coins(多重背包优化)
- POJ - 1742 Coins(多重背包)@
- poj 1742Coins(混合背包)
- poj 1742 coins 背包问题
- poj 1742 Coins(多重背包)
- poj 1742 Coins(多重背包)
- POJ-1742-多重背包-Coins
- POJ 1742 Coins (多重背包)
- 相隔日期有多少天多少时
- CStdioFile类
- hibernate初始化
- DB2 SQL自学笔记
- 自己电脑做服务器续,用默认端口,自动跳转到默认项目 【直接用域名访问我们本机的项目】
- poj 1742 Coins (背包)
- 视频快搜新片热剧,百度手机浏览器上都有啊
- Debug Assertion Failed! File:afxwin1.inl Line:22
- mybatis 对oracle和mysql 批量插入操作
- re模糊查询
- 网络流量计费程序(4)
- dofile, loadfile, loadstring, require, module
- vmWare上运行VxWorks
- mysql 用户登录密码忘记处理