Bone Collector【01背包】

F - Bone Collector

 HDU - 2602 

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 2 31).

Sample Input

1
5 10
1 2 3 4 5
5 4 3 2 1

Sample Output

14

 

AC代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n,v;
int c[1100],w[1100];
int f[1100];
int zeroone()
{for(int i=1;i<=n;i++)for(int j=v;j>=c[i];j--)f[j]=max(f[j],f[j-c[i]]+w[i]);return f[v];
}
int main()
{int num;cin>>num;while(num--){memset(f,0,sizeof(f));cin>>n>>v;for(int i=1;i<=n;i++)cin>>w[i];for(int i=1;i<=n;i++)cin>>c[i];cout<<zeroone()<<endl;}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/536414.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Gamma阶段第八次scrum meeting

每日任务内容 队员昨日完成任务明日要完成的任务张圆宁#91 用户体验与优化https://github.com/rRetr0Git/rateMyCourse/issues/91&#xff08;持续完成&#xff09;#91 用户体验与优化https://github.com/rRetr0Git/rateMyCourse/issues/91牛宇航#86 重置密码的后端逻辑https:/…

【动态规划】多重背包

问题 Q: 【动态规划】多重背包 时间限制: 1 Sec 内存限制: 64 MB 提交: 112 解决: 49 [提交] [状态] [讨论版] [命题人:admin] 题目描述 张琪曼&#xff1a;“魔法石矿里每种魔法石的数量看起来是足够多&#xff0c;但其实每种魔法石的数量是有限的。” 李旭琳&#xff1a;…

【动态规划】完全背包问题

问题 O: 【动态规划】完全背包问题 时间限制: 1 Sec 内存限制: 64 MB 提交: 151 解决: 71 [提交] [状态] [讨论版] [命题人:admin] 题目描述 话说张琪曼和李旭琳又发现了一处魔法石矿&#xff08;运气怎么这么好&#xff1f;各种嫉妒羡慕恨啊&#xff09;&#xff0c;她们有…

springboot超级详细的日志配置(基于logback)

前言 java web 下有好几种日志框架&#xff0c;比如&#xff1a;logback&#xff0c;log4j&#xff0c;log4j2&#xff08;slj4f 并不是一种日志框架&#xff0c;它相当于定义了规范&#xff0c;实现了这个规范的日志框架就能够用 slj4f 调用&#xff09;。其中性能最高的应该使…

【动态规划】简单背包问题II

问题 J: 【动态规划】简单背包问题II 时间限制: 1 Sec 内存限制: 64 MB 提交: 127 解决: 76 [提交] [状态] [讨论版] [命题人:admin] 题目描述 张琪曼&#xff1a;“为什么背包一定要完全装满呢&#xff1f;尽可能多装不就行了吗&#xff1f;” 李旭琳&#xff1a;“你说得…

Vue组件通信

前言 Vue组件之间的通信 其实是一种非常常见的场景 不管是业务逻辑还是前段面试中都是非常频繁出现的 这篇文章将会逐一讲解各个传值的方式 不过在此之前 先来总结一下各个传值方式吧 1.父组件向子组件传值 > props2.子组件向父组件传值 > $emit3.平级组件传值 > 总线…

【动态规划】0/1背包问题

问题 H: 【动态规划】0/1背包问题 时间限制: 1 Sec 内存限制: 64 MB 提交: 152 解决: 95 [提交] [状态] [讨论版] [命题人:admin] 题目描述 张琪曼和李旭琳有一个最多能用m公斤的背包&#xff0c;有n块魔法石&#xff0c;它们的重量分别是W1&#xff0c;W2&#xff0c;…&a…

猫哥教你写爬虫 005--数据类型转换-小作业

小作业 程序员的一人饮酒醉 请运用所给变量&#xff0c;使用**str()**函数打印两句话。 第一句话&#xff1a;1人我编程累, 碎掉的节操满地堆 第二句话&#xff1a;2眼是bug相随, 我只求今日能早归 number1 1 number2 2 unit1 人 unit2 眼 line1 我编程累 line2 是bug相…

索引失效

转载于:https://blog.51cto.com/11009785/2406488

棋盘问题【深搜】

棋盘问题 POJ - 1321 在一个给定形状的棋盘&#xff08;形状可能是不规则的&#xff09;上面摆放棋子&#xff0c;棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列&#xff0c;请编程求解对于给定形状和大小的棋盘&#xff0c;摆放k个棋子的所有可行…

python isinstance()

isinstanceisinstance(object, classinfo) 判断实例是否是这个类或者object是变量 classinfo 是类型(tuple,dict,int,float) 判断变量是否是这个类型 举例&#xff1a; class objA: pass A objA() B a,v C a string print isinstance(A, objA) #注意该用法 print isinst…

P1303 A*B Problem 高精度乘法

复习了一下高精乘 #include<bits/stdc.h> using namespace std; const int maxn1e67; char a1[maxn],b1[maxn]; int a[maxn],b[maxn],c[maxn*10],lena,lenb,lenc,x; int main() {scanf("%s",a1);scanf("%s",b1);lenastrlen(a1);lenbstrlen(b1);for(i…

Catch That Cow【广搜】

Catch That Cow POJ - 3278 Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number l…

Go2Shell 已无法使用

在更新 Mac 系统时提醒了这个, 像我一样对 Go2Shell 中毒的人来说, 这是无法忍受的。貌似 Go2Shell 没有升级&#xff0c;没有办法&#xff0c;就直接找来了一个替代品。cd to, 下载入口如下&#xff1a;目前感觉良好。 转载于:https://juejin.im/post/5cfe82e15188252b1b0366e…

Fliptile【搜索】

Fliptile POJ - 3279 Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M N grid (1 ≤ M ≤ 15; 1 ≤ N ≤ 15) of square tiles, each of which…

JS异步开发总结

1 前言 众所周知&#xff0c;JS语言是单线程的。在实际开发过程中都会面临一个问题&#xff0c;就是同步操作会阻塞整个页面乃至整个浏览器的运行&#xff0c;只有在同步操作完成之后才能继续进行其他处理&#xff0c;这种同步等待的用户体验极差。所以JS中引入了异步编程&…

迷宫问题【广搜】

迷宫问题 POJ - 3984 定义一个二维数组&#xff1a; int maze[5][5] {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,}; 它表示一个迷宫&#xff0c;其中的1表示墙壁&#xff0c;0表示可以走的路&#xff0c;只能横着走或竖着走&#xff0c;不能…

大虾对51单片机入门的经验总结

回想起当初学习AT89S52的日子还近在眼前:毕业后的第一年呆在亲戚公司做了10个月设备管理.乏味的工作和繁杂的琐事让我郁闷不已.思考很久后终于辞职.投奔我的同学去了,开始并不曾想到要进入工控行业,知识想找一份电子类技术职业,至于什么职业我根本没有目标可言.经过两个多月的挫…

mac安装cnpm

1.先安装node node的下载地址&#xff1a;http://nodejs.cn/download/ 这个没什么好说的&#xff0c;安装完成后测试一下&#xff0c;在终端输入&#xff1a;node -v 这时候就可以看到安装的node版本号&#xff0c;再输入&#xff1a;npm -v 这时候就会看到npm的版本号了 2.用n…

A计划【广搜】

A计划 HDU - 2102 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后&#xff0c;而今&#xff0c;不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主&#xff0c;因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚&#xff0c;告招天…