Bone Collector

Time Limit: 1000ms
Memory Limit: 32768KB
 
This problem will be judged on HDU. Original ID: 2602
64-bit integer IO format: %I64d      Java class name: Main
 
 
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).

 

Sample Input

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

Sample Output

14
 

Source

 
 
解题:0-1背包。。。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <ctype.h>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
int v[],w[],dp[];
int main(){
int kase,i,j,n,m;
scanf("%d",&kase);
while(kase--){
memset(dp,,sizeof(dp));
scanf("%d %d",&n,&m);
for(i = ; i <= n; i++)
scanf("%d",v+i);
for(i = ; i <= n; i++)
scanf("%d",w+i);
for(i = ; i <= n; i++){
for(j = m; j >= w[i]; j--){
dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
}
}
printf("%d\n",dp[m]);
}
return ;
}

最新文章

  1. 关于js中的this之判断this
  2. monkeyrunner之坐标或控件ID获取方法-续
  3. solr索引服务器的配置和solrj集成开发总结
  4. Creating, Stopping, Re-Starting and Deleting a Timer in Oracle Forms
  5. [Angular 2] Child Router
  6. Java 之String.valueOf(obj)
  7. MVC是一种用于表示层设计的复合设计模式
  8. 遇到build的问题
  9. javascript学习笔记-4
  10. Spring框架学习之--搭建spring框架
  11. IT题库1-HashMap、HashSet和HashTable(区别?数据格式?)
  12. C++ 一些特性
  13. easyui中combobox 取值
  14. Python文件读写、StringIO和BytesIO
  15. DBA的规范
  16. OpenGL 画出雷达动态扫描效果(一)
  17. [JSOI2008]火星人
  18. MT【142】Bachet 问题,进位制
  19. 谷歌技术&quot;三宝&quot;之谷歌文件系统(转)
  20. 【sklearn】性能度量指标之ROC曲线(二分类)

热门文章

  1. Java方式配置Spring MVC
  2. [转载]深入理解Java 8 Lambda
  3. Vuex.js状态管理共享数据 - day8
  4. 解决更新到os x10.11后openssl头文件无法找到的问题
  5. ZOJ 3466 The Hive II (插头DP,变形)
  6. Python学习日志9月17日 一周总结
  7. 前端性能优化:细说JavaScript的加载与执行
  8. gdb插件使用方法
  9. 伪题解 洛谷 P1363 幻想迷宫(DFS)
  10. passive event 解决方法