HDU-2602-Bone Collector
2016-03-23 21:31
381 查看
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 45832 Accepted Submission(s): 19075
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
01背包 动规基础题
状态转移方程:dp[j]=max(dp[j],dp[j-num[i].体积]+num[i].价值
代码
背包 背包 背包
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 45832 Accepted Submission(s): 19075
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
01背包 动规基础题
状态转移方程:dp[j]=max(dp[j],dp[j-num[i].体积]+num[i].价值
代码
#include<iostream> #include<algorithm> #include<math.h> #include<string> #include<string.h> #include<stdio.h> #include<queue> using namespace std; //01背包 struct node { int value;//价值 int volume;//体积 } num[1005]; int dp[1005]; int main() { int T; scanf("%d",&T); while(T--) { memset(dp,0,sizeof(dp)); int N;//数量 int max_v;//背包最大体积 scanf("%d%d",&N,&max_v); for(int i=0; i<N; i++) scanf("%d",&num[i].value); for(int i=0; i<N; i++) scanf("%d",&num[i].volume); for(int i=0; i<N; i++) { for(int j=max_v; j>=num[i].volume; j--) { dp[j]=max(dp[j],dp[j-num[i].volume]+num[i].value); } } printf("%d\n",dp[max_v]); } return 0; }
背包 背包 背包
相关文章推荐
- Objective-C:单例模式
- 《世界是数字的》读书笔记
- less的结构嵌套和变量作用域
- LCS简单问题
- 通达OA 小飞鱼工作流在线培训教程文件夹及意见征集
- js练习-控制div属性
- 模拟算法_掷骰子游戏&&猜数游戏
- Java异常处理总结
- Android中设计模式--状态模式(将动作委托到当前状态,状态之间可以互相转换)
- 智能指针的模拟实现shared_ptr 循环引用 定置删除器
- [LeetCode 253] Meeting Rooms II
- 字符个数统计
- 自定义Js温馨提示窗
- leetcode 35. Search Insert Position
- 机器学习:过拟合和交叉印证
- Android之下拉刷新的ListView
- JS复习--更新结束
- 《java中局部变量和成员变量的区别》
- 1001 ACID 00731031
- 找工作——jvm复习(三)