Bone Collector
来源:互联网 发布:大数据的实践包括 编辑:程序博客网 时间:2024/05/22 12:56
Bone Collector
Time Limit: 1000MS Memory Limit: 65536KB
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).
Example Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Example Output
14
对于英语头痛的我来说英语题比上天还难,没办法,咱有神器,谷歌翻译,经过谷歌一翻译,我发现这就是一个01背包的模板题。
#include <stdio.h>#include <string.h>int main(){ int t,n,m; int a[1010],b[1010]; int f[1010]; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for (int i=0;i<n;i++){ scanf("%d",&a[i]); } for (int i=0;i<n;i++){ scanf("%d",&b[i]); } memset(f,0,sizeof(f)); for (int i=0;i<n;i++){ for (int j=m;j>=b[i];j--){ if (f[j]<f[j-b[i]]+a[i]){ f[j]=f[j-b[i]]+a[i]; } } } printf("%d\n",f[m]); } return 0;}
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Struts2 ActionInvocation
- 工具类-线程池
- ContentObserver内容监听者(内容观察者)
- Eclipse / MyEclipse中断点调试的基本使用
- JZ006 connection refused
- Bone Collector
- zookeeper配置文件详解
- 小悟方法重载
- Apache2+Tomcat7负载均衡配置(超详细整合文档)
- Problem on Group Trip UVALive - 7219 (模拟+优先队列处理)
- 2016多校训练1 hdu5733 tetrahedron
- Linux学习笔记之文件备份和还原
- HBuilder之MUI开发
- ANR分析(二)