HDU 2602 Bone Collector(01背包裸题)
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 60469 Accepted Submission(s): 25209
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
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602
题意:一个叫做Bone Collector的男的有一个包,往包里放东西,使得其价值最大。
输入:注意是先输入的是价值,后是体积。
分析:01背包裸题,注意格式输入输出就行了,我就是输入格式写错了,找错误找了一个小时,QAQ
下面给出AC代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int n;
6 int v[1010],dp[1010],d[1010];//v代表体积,d代表谷歌值
7 while(scanf("%d",&n)!=EOF)
8 {
9 while(n--)
10 {
11 memset(v,0,sizeof(v));
12 memset(dp,0,sizeof(dp));
13 memset(d,0,sizeof(d));
14 int x,y;
15 cin>>x>>y;
16 for(int i=1;i<=x;i++)
17 cin>>d[i];
18 for(int i=1;i<=x;i++)
19 cin>>v[i];
20 for(int i=1;i<=x;i++)//01背包主函数
21 {
22 for(int j=y;j>=v[i];j--)
23 {
24 dp[j]=max(dp[j],dp[j-v[i]]+d[i]);
25 }
26 }
27 printf("%dn",dp[y]);
28 }
29 }
30 return 0;
31 }
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 一天一大 leet(字符串相加)难度:简单-Day20200803
- 一天一大 lee(恢复二叉搜索树)难度:困难-Day20200808
- 一天一大 leet(最小区间)难度:困难-Day20200801
- 一天一大 lee(全排列 II)难度:中等-Day20200918
- 一天一大 lee(冗余连接 II)难度:困难-Day20200917
- 一天一大 lee(左叶子之和)难度:简单-Day20200919
- 【一天一大 lee】 把二叉搜索树转换为累加树 (难度:简单)-Day20200921
- 【一天一大 lee】子集 (难度:中等)-Day20200920
- 用了这个jupyter插件,我已经半个月没打开过excel了
- Webpack学习笔记
- 正则表达式学习笔记
- R 可视化 | 华夫饼图
- 绝了!Python定时爬取微博热搜+pyecharts动态图展示
- 实战 | Python爬取B站柯南弹幕+Gephi梳理主线剧情
- 别再问我 Python 怎么识别数字验证码了!