hdoj 2602 Bone Collector【裸0-1背包】
2016-04-09 09:13
363 查看
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 46309 Accepted Submission(s): 19282
Problem Description
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 ?
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.
Output
One integer per line representing the maximum of the total value (this number will be less than 231).
Sample Input
1 5 10 1 2 3 4 5 5 4 3 2 1
Sample Output
14
Author
Teddy
Source
HDU 1st “Vegetable-Birds Cup” Programming
Open Contest
Recommend
lcy | We have carefully selected several similar problems for you: 2159 1171 1003 2844 1087
Statistic | Submit | Discuss | Note
代码:
//裸0-1背包 #include <stdio.h> #include <string.h> #include <algorithm> #define INF 0x3f3f3f3f #define max(a,b) (a>b)?a:b using namespace std; int val[1005],vi[1005]; int dp[1005]; int main() { int T; scanf("%d",&T); while(T--) { int n,v; scanf("%d%d",&n,&v); for(int i=0;i<n;i++) scanf("%d",&val[i]); for(int i=0;i<n;i++) scanf("%d",&vi[i]); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { for(int j=v;j>=vi[i];j--) { dp[j]=max(dp[j],dp[j-vi[i]]+val[i]); } } printf("%d\n",dp[v]); } return 0; }
相关文章推荐
- 详细介绍VO和PO的区别
- 144.⑨要写信(错排公式与高精度练习)
- java之其它命令
- java之javadoc命令
- java之jar命令详解
- 用 JavaScript 对抗 DDOS 攻击
- hdoj 2955 Robberies【对立事件+0-1背包】
- 物联网与穿戴设备专题(1)
- BigInteger类型的解析_超详细解析
- 对于大学4年的反思(续),记我的ThoughtWorks面试
- android中 代码实现截图功能(静态+动态视频)
- LeetCode 121. Best Time to Buy and Sell Stock
- iOS单例的作用和使用
- java之classpath到底是什么
- 模拟实现 printf 函数
- hdoj 2546 饭卡 【转化思维+0-1背包】
- 操作系统中常用的调度算法
- 初始化顺序、==、AB交换
- 07_计算三位数中的所有“水仙花数”
- 时间复杂度和空间复杂度[数据结构]