hduoj 2602Bone Collector
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 40598 Accepted Submission(s): 16872
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 ?
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.
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<stack> 5 #include<set> 6 #include<map> 7 #include<queue> 8 #include<algorithm> 9 using namespace std; 10 #define max(a,b) (a>b?a:b) 11 int va[1005],vo[1005],dp[1005][1005]; 12 int main() 13 { 14 //freopen("D:\\INPUT.txt","r",stdin); 15 int t,i,j; 16 int n,v; 17 scanf("%d",&t); 18 while(t--) 19 { 20 scanf("%d %d",&n,&v); 21 for(i=1; i<=n; i++) 22 { 23 scanf("%d",&va[i]); 24 } 25 for(i=1; i<=n; i++) 26 { 27 scanf("%d",&vo[i]); 28 } 29 //dp[i][j] 前i件物品放入j体积的价值的最大值 30 //dp[i][j]=max(dp[i-1][j],dp[i-1][j-vo[i]]+va[i]) 31 for(i=1; i<=n; i++) //i体积 32 { 33 for(j=0; j<=v; j++) 34 { 35 if(j>=vo[i]){ 36 dp[i][j]=max(dp[i-1][j],dp[i-1][j-vo[i]]+va[i]); 37 } 38 else{ 39 dp[i][j]=dp[i-1][j]; 40 } 41 42 //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl; 43 } 44 } 45 printf("%d\n",dp[n][v]); 46 } 47 return 0; 48 }
转载于:https://www.cnblogs.com/Deribs4/p/4796120.html
hduoj 2602Bone Collector相关推荐
- HDOJ 2602-Bone Collector(0/1背包模板、打印方案及滚动数组解法)
0/1背包 一.Bone Collector 解法一:二维数组解法(0/1背包模板代码) 1.1 0/1背包打印方案代码 解法二:滚动数组(一维)解法 2.1 一维滚动数组例题 E-爱玩游戏的Tom ...
- 动态规划(五)——0/1背包
0/1背包 一.0/1背包问题 1.实例讲解 2.DP求解0/1背包 3.输出0/1背包方案 二.0/1背包题目代码(持续更新) 一.0/1背包问题 给定n种物品和一个背包,物品i的重量为wi,价值为 ...
- java中collection方法_Java 8中的Collector toCollection()方法
toCollection()Java中的Collector类的方法返回一个Collector,该Collector以遇到的顺序将输入元素累积到一个新的Collection中. 语法如下static & ...
- 在Data Collector中使用TensorFlow进行实时机器学习
导言 只有当业务方面的用户和应用程序能够从一系列来源访问原始和聚合数据,并及时生成数据驱动时,才能实现现代DataOps平台的真正价值.借助机器学习,分析师和数据科学家可以利用TensorFlow等技 ...
- Java-JVM虚拟机内存垃圾回收机制gc入门:引用类型,对象标记算法,回收算法,常见的 garbage collector
文章目录 GC的优缺点 引用的四种类型 对象标记算法 引用计数法 可达性分析法 回收算法 标记-清除算法(Mark-Sweep) 复制算法 标记-整理算法(Mark-Compact) 分代收集算法 常 ...
- Ambari安装之部署 (Metrics Collector和 Metrics Monitor) Install Pending ...问题
问题详细描述如下: Metrics Collector的解决办法 正在重新安装 Metrics Monitor的解决办法 Metrics Collector和 Metrics Monitor 的I ...
- HDU 2602 Bone Collector DP(01背包)
Bone Collector Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
- Exchange Log Collector Script
A while ago I created the "CollectLogsScript" (see my old A better way to collect logs fro ...
- HDUOJ 1060 Leftmost Digit
问题:求x^x的最高位 思路: 假设a = x^x,对10求对数有log(a) = x * log(x) = b.cd,其中b表示指数的最大表示,10^(.cd)就是底 具体代码参考: https:/ ...
- jmeter插件 --PerfMon Metrics Collector监控工具的使用
PerfMon Metrics Collector 用来监控 被压测服务器的cpu.内存.磁盘.网络等 1.服务端监控程序ServerAgent下载 https://github.com/undera ...
最新文章
- spring之AOP(转)
- i.e.、e.g.、etc.都是什么英文的缩写?
- hust1341(模拟)
- iOS之深入解析AFNetworking的底层原理
- LeetCode动态规划 最大子序和
- php json_encode 替代方法 (亦可显示中文)
- MySQL实战 | 01 当执行一条 select 语句时,MySQL 到底做了啥?
- java中volatile关键字的含义_Java里volatile关键字是什么意思
- java 读取 tgz_java – 从Spark中的压缩中读取整个文本文件
- python画简便的图-python中简单易学的绘图:用turtle画太极图
- 青少年计算机编程赛,青少年编程竞赛汇总
- (附源码)php积极心理学交流网站 毕业设计 100623
- 中国经济形势开年如何看?
- Android系统基础介绍
- 用户运营中,怎么做好用户增长?
- 两年工作经验程序员的迷茫
- CSA创建用户以及组、管理用户密码、简单用户身份切换
- jmq java_互联网+技术 | 京东消息中间件JMQ的演进
- R统计绘图 | 物种组成堆叠柱形图(绝对/相对丰度)
- 基于KNN的分类模型-预测美团外卖城市等级
热门文章
- Java8初体验(一)lambda表达式语法
- 关于Mysql5.5在关键字方面的变化
- linux 17 中文输入,Rethat Linux Fedora17添加中文输入法
- gettype拿不到值_这五种古董,别说是买豪车豪宅,放在现实中最多就值一顿饭钱...
- redission分布式锁测试代码
- Springboot2.x 集成 jedis和spring-boot-starter-data-redis的性能测试比较(Jedis完胜:附带源码)
- sourcetree合并分支_不会git命令,没关系啊,还有强大的图形界面工具SourceTree
- 【渝粤教育】国家开放大学2018年秋季 0727-22T思想道德修养与法律基础 参考试题
- 【渝粤教育】 广东开放大学21秋期末考试法律文书10684k2
- 23种设计模式(十五)接口隔离之适配器