hdu 2602 and poj 3624(01背包)
来源:互联网 发布:彩票11选5遗漏数据分析 编辑:程序博客网 时间:2024/05/16 11:05
01背包的模板题。
hdu2602代码:
#include<stdio.h>#include<string.h>const int MaxN = 1001;int max(int a, int b){ return a > b ? a : b;}int w[MaxN];int v[MaxN];int dp[MaxN];int main(){ int T; int N, V; scanf("%d", &T); while(T--) { scanf("%d%d", &N, &V); for(int i = 1; i <= N; i++) { scanf("%d", &w[i]); } for(int i = 1; i <= N; i++) { scanf("%d", &v[i]); } memset(dp, 0, sizeof(dp)); for(int i = 1; i <= N; i++) { for(int l = V; l >= v[i]; l--) { dp[l] = max(dp[l], dp[l - v[i]] + w[i]); } } printf("%d\n", dp[V]); } return 0;}
poj3264:
#include<stdio.h>#include<string.h>const int MaxN = 3403;const int MaxV = 12881;//debugint w[MaxN];int d[MaxN];int dp[MaxV];int max(int a, int b){ return a>b?a:b;}int main(){ int N, M; scanf("%d%d", &N, &M); for(int i = 1; i <= N; i++) { scanf("%d%d", &w[i], &d[i]); } memset(dp, 0, sizeof(dp)); for(int i = 1; i <= N; i++) { for(int v = M; v >= w[i]; v--) { dp[v] = max(dp[v], dp[v - w[i]] + d[i]); } } printf("%d\n", dp[M]); return 0;}
0 0
- hdu 2602 and poj 3624(01背包)
- HDU 5464 Clarke and problem(01背包)
- HDU-5188-zhx and contest【01背包】
- 01 背包 poj 3624
- poj 3624 01背包
- poj 3624 01 背包
- poj 3624 01背包
- poj 3624 01背包
- POJ 3624 01背包
- POJ-3624 01背包
- poj 3624(01背包)
- poj 3624 01背包
- POJ-3624-01背包
- hdu 5410 CRB and His Birthday(01背包+完全背包)
- HDU 5410 CRB and His Birthday (01背包+完全背包)
- hdu 5410 CRB and His Birthday(01背包+完全背包)
- HDU 5410 CRB and His Birthday(完全背包,01背包)
- HDU 2602 01背包
- Web Services 平台元素
- 在虚拟机上安装Ubuntu以及在Windows下配置PHP环境
- Linux编程实践----第一个多线程程序
- hibernate中利用criteria分页的实现
- Linux的inode的理解
- hdu 2602 and poj 3624(01背包)
- ZooKeeper应用实例:Java实现与ZooKeeper的连接
- C#中使用Split分隔字符串的技巧
- Mysql 获取排列序号。
- Java线程(一):线程安全与不安全
- Android ListView字母索引(仿微信通讯录列表)
- CGI如何用C控制sqlite3?
- Python 中的文件读写(一)
- Java 并发模式之Master-Worker