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