Bone Collector(01背包,模板题)
来源:互联网 发布:义乌聚宝软件 编辑:程序博客网 时间:2024/05/16 17:21
C - Bone Collector
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
Input
The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
Output
One integer per line representing the maximum of the total value (this number will be less than 231).
Sample Input
15 101 2 3 4 55 4 3 2 1
Sample Output
14 AC代码:#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1010;int n, vb;int r[MAXN], v[MAXN];int dp[MAXN][MAXN];int rec(int i, int j){ if (dp[i][j] >= 0) { return dp[i][j]; } int res; if (i == n) { res = 0; } else if (j < r[i]) { res = rec(i + 1, j); } else { res = max (rec(i + 1, j), rec(i + 1, j - r[i]) + v[i]); } return dp[i][j] = res;}int main(){ int t; scanf("%d", &t); while (t--) { memset(r, 0, sizeof (r)); memset(v, 0, sizeof (v)); memset(dp, -1, sizeof (dp)); scanf("%d%d", &n, &vb); for (int i=0; i<n; i++) { scanf("%d", &v[i]); } for ( int i=0; i<n; i++) { scanf("%d", &r[i]); } printf("%d\n", rec(0, vb)); } return 0;}
一次A了!
0 0
- Bone Collector(01背包,模板题)
- HDU2602-Bone Collector-01背包(模板题)
- Bone Collector 01背包模板
- Bone Collector(01背包模板)
- HDU2602 01背包入门 Bone Collector【01背包模板题】
- HDU2602 Bone Collector 01背包DP 模板题
- HDOJ 2602 Bone Collector(01背包最基本模板题)
- Bone Collector 2602 (01背包)(模板)
- HDU 2602 Bone Collector (01背包模板)
- 杭电-2602 Bone Collector(01背包模板)
- HDU2602 Bone Collector(01背包模板 一维数组)
- hdu 2062 Bone Collector -- 01背包模板
- hdu 2602 Bone Collector 【01背包模板】
- HDU-2602-Bone Collector【01背包模板】
- hud 2602 Bone Collector (0_1背包模板题)
- Bone Collector(01背包)
- Bone Collector(01背包)
- Bone Collector(01背包)
- 客户端携带版本号码去访问服务端
- 第4课:Spark Streaming的Exactly-One的事务处理和不重复输出彻底掌握
- myeclipse10.1破解方法
- Spark学习路线
- 运行Hadoop start-all.sh遇到的错误ssh: connect to host localhost port 22: Connection refused
- Bone Collector(01背包,模板题)
- Trapping Rain Water
- Bugzilla使用手册及解决方案
- jquery实现表格中点击相应行变色功能
- R神经网络(amore)
- 感觉蛮有用的东西
- 排序算法(综述)
- 各种信息图应用说明
- WebStorm添加多个项目到当前工程目录