hdu2602 Bone Collector-01背包问题
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背包问题!
代码如下:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int dp[N][N];
int n, V;struct BONE {int val;int vol;
} bone[N];int ans() {memset(dp, 0, sizeof(dp));for (int i = 1; i <= n; i++)for (int j = 0; j <= V; j++) {if (bone[i].vol > j)dp[i][j] = dp[i - 1][j];else {dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - bone[i].vol] + bone[i].val);}}return dp[n][V];
}int main() {int cnt;cin >> cnt;while (cnt--) {cin >> n >> V;for (int i = 1; i <= n; i++)cin >> bone[i].val;for (int i = 1; i <= n; i++)cin >> bone[i].vol;cout << ans() << endl;}return 0;
}
hdu2602 Bone Collector-01背包问题相关推荐
- HDU Bone Collector (01背包问题)
之前背包问题学了忘学了忘= =是太笨了. 题目 许多年前,在泰迪的家乡,有一个人被称为"骨收集者".这个人喜欢收集各种骨头,例如狗,牛的骨头,他也去了坟墓-- 骨头收集者有一个大袋 ...
- HDU2602 Bone Collector【0/1背包+DP】
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 2602 Bone Collector 01背包
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu2602——Bone Collector
01背包问题! 1.现在的f[v-c[i]]就相当于原来的f[i-1][v-c[i]]; 2. f[i][v]表示前i件物品恰放入一个容量为v的背包可以获得的最大价值. #include<std ...
- Bone Collector(01背包问题-两种写法)
Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This ...
- Bone Collector(骨头收集者)c++(01背包问题)
题目来源:杭州电子科技大学 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- Bone Collector(HDU-2602)
Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...
- HDU 2602 Bone Collector DP(01背包)
Bone Collector Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
最新文章
- android drawerlayout 遮罩层白色,DrawerLayout放在Toolbar的下方导致NavigationView出现与状态栏等高的遮...
- 《编程之美》读书笔记08:2.9 Fibonacci序列
- MPlayer1.1.1移植记录
- 将一个数字划分成树状
- spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient 1
- 23种设计模式(8)-外观模式
- input中radio对象的使用、获取方法
- css3 border-radius详解
- 《电机学和电机驱动入门》
- 配置管理计划的主要内容有哪些?
- 良心安利东方 rpg游戏制作大师素材网站
- Intel正式发布新一代Atom处理器
- 输入经纬度在地图中标注位置(百度地图)
- HarmonyOS的万里长征和万里长城
- 【坐标轴移位+主辅刻度设定】两年梳理一次性清晰的展示出来,大图解析学习超简单
- 【leetcode刷题】找到需补充粉笔的学生编号
- 怎么给自己的电脑连接打印机
- 赋予DBLINK权限
- 什么是频分双工(FDD)/时分双工(TDD)
- 电脑上office2010安装包下载安装教程
热门文章
- Android之稍微靠谱点的透明Activity(不获取触摸事件)
- linux c之用fopen、fputs、fgets、 fseek来对文件进行写、替换、读
- Android 之PackageManager框架
- Android面试题总结加强再加强版(三)
- 赶紧3分钟学完15分钟的内容我要出去玩(8)
- python中lines是什么类型_Python中splitlines()方法的使用简介
- c2000 汇编语言指令,C2000系CMD文件的配置理解
- python正十三边形_一起学python-opencv十三(直方图反向投影和模板匹配)
- python多线程读取数据库数据_Python基于多线程操作数据库相关知识点详解
- 那些喜欢少妇的男生......