博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2602 Bone Collector
阅读量:6282 次
发布时间:2019-06-22

本文共 1980 字,大约阅读时间需要 6 分钟。

Bone Collector
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit     
Appoint description: System Crawler  (2017-04-13)

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

Sample Input

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

Sample Output

14
 一个简单的01背包问题
#include
#include
#include
using namespace std;long long a[1010],v[1010];long long dp[1010];int n,res;long long max(long long a,long long b){ if(a>=b) return a; else return b;}int main(){ int T; while( cin >> T ) { while( T -- ) { cin >> n >> res; for(int i=0; i
> v[i]; for(int j=0; j
> a[j]; memset(dp,0,sizeof(dp));//初始化 for(int i=0; i
=a[i]; j--) { dp[j] = max(dp[j], dp[j-a[i]]+v[i]);//01背包,理解 } } cout << dp[res] << endl; } } return 0;}

 

转载于:https://www.cnblogs.com/l609929321/p/6706389.html

你可能感兴趣的文章
简单易懂的谈谈 javascript 中的继承
查看>>
iOS汇编基础(四)指针和macho文件
查看>>
Laravel 技巧锦集
查看>>
Android 使用 ViewPager+RecyclerView+SmartRefreshLayout 实现顶部图片下拉视差效果
查看>>
Flutter之基础Widget
查看>>
写给0-3岁产品经理的12封信(第08篇)——产品运营能力
查看>>
ArcGIS Engine 符号自动化配置工具实现
查看>>
小程序 · 跳转带参数写法,兼容url的出错
查看>>
flutter error
查看>>
Flask框架从入门到精通之模型数据库配置(十一)
查看>>
10年重新出发
查看>>
2019年-年终总结
查看>>
聊聊elasticsearch的RoutingService
查看>>
让人抓头的Java并发(一) 轻松认识多线程
查看>>
从源码剖析useState的执行过程
查看>>
地包天如何矫正?
查看>>
中间件
查看>>
Android SharedPreferences
查看>>
css面试题
查看>>
Vue组建通信
查看>>