HDU 2602Bone Collector(01背包)
来源:互联网 发布:免费下载翻译软件 编辑:程序博客网 时间:2024/06/14 05:12
Bone Collector
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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 ?
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.
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
15 101 2 3 4 55 4 3 2 1
Sample Output
14
Author
总结:裸裸的01背包
//// main.cpp// Bone Collector//// Created by 张嘉韬 on 16/8/8.// Copyright © 2016年 张嘉韬. All rights reserved.//#include <iostream>#include <cstring>#include <cstdio>#include <cmath>using namespace std;const int maxn=1000+10;int f[maxn][maxn],w[maxn],v[maxn];int main(int argc, const char * argv[]) { // freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin); int T; cin>>T; while(T--) { int n,p; memset(f,0,sizeof(f)); scanf("%d%d",&n,&p); for(int i=1;i<=n;i++) scanf("%d",&v[i]); for(int i=1;i<=n;i++) scanf("%d",&w[i]); for(int i=1;i<=n;i++) { for(int j=0;j<=p;j++) { if(j-w[i]<0) f[i][j]=f[i-1][j]; else f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+v[i]); } } int maximum=0; for(int i=0;i<=p;i++) if(f[n][i]>maximum) maximum=f[n][i]; cout<<maximum<<endl; } return 0;}
0 0
- hdu 2602 Bone Collector (01背包)
- hdu 2602 Bone Collector(01背包)
- HDU 2602 Bone Collector( 01背包 )
- HDU 2602 Bone Collector(01背包)
- HDU 2602 Bone Collector(01背包)
- HDU 2602 Bone Collector (01背包)
- HDU 2602 Bone Collector(01背包)
- HDU 2602 Bone Collector(01背包)
- hdu 2602 Bone Collector (01背包)
- hdu 2602 Bone Collector(01背包)
- HDU 2602 Bone Collector(01背包)
- HDU - 2602 Bone Collector (01背包)
- HDU 2602 Bone Collector (01背包)
- HDU 2602 Bone Collector (01背包)
- HDU 2602 Bone Collector(01背包)
- hdu 2602 Bone Collector(01背包)
- HDU 2602 Bone Collector(01背包)
- HDU 2602 Bone Collector(01背包)
- SHELL日志分析 实例一
- ideal断点变为叉
- 老版firefox运行npapi插件问题排查
- java工具类1---一般是通过静态函数实现某个功能,而不需要涉及类的任何属性和变量,直接类名调用
- Spring源码分析【5】-Spring MVC处理流程
- HDU 2602Bone Collector(01背包)
- 欢迎使用CSDN-markdown编辑器---备忘
- 关于阻塞/非阻塞/同步/异步问题
- 共享内存
- Android NDK系列(3) --- ARM寄存器
- json C C++
- html, js 定时自动刷新本页
- 移植uboot第二步:分析uboot
- ubuntu 16.04.1设置静态ip、dns