Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 57334    Accepted Submission(s): 23933

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).
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
Author
Teddy
Source
01背包 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define N 10000
typedef long long ll;
using namespace std;
int value[N],vloume[N];
int dp[N];
int main()
{
int t;
scanf("%d",&t);
int n,v;
while(t--)
{
memset(value,0,sizeof(value));
memset(vloume,0,sizeof(vloume));
memset(dp,0,sizeof(dp));
scanf("%d%d",&n,&v);
for(int i=0;i<n;i++)
scanf("%d",&value[i]);
for(int i=0;i<n;i++)
scanf("%d",&vloume[i]);
for(int i=0;i<n;i++)
{
for(int j=v;j>=vloume[i];j--)
{
dp[j]=max(dp[j],dp[j-vloume[i]]+value[i]);
}
}
printf("%d\n",dp[v]);
}
}

hdu 2602(经典01背包)的更多相关文章

  1. hdu 2602 简单0-1背包模板题

    #include<stdio.h> #include<string.h> #define N 1100 int dp[N]; int main() { int n,t,m,a[ ...

  2. hdu 2546 典型01背包

    分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意 ...

  3. hdu 2602 Bone Collector 背包入门题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...

  4. ACM HDU Bone Collector 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有 ...

  5. HDU 2639(01背包求第K大值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Jav ...

  6. hdu 2955 Robberies (01背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...

  7. hdu 3466 排序01背包

    也是好题,带限制的01背包,先排序,再背包 这题因为涉及到q,所以不能直接就01背包了.因为如果一个物品是5 9,一个物品是5 6,对第一个进行背包的时候只有dp[9],dp[10],…,dp[m], ...

  8. hdu 2955 Robberies 0-1背包/概率初始化

    /*Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  9. HDU 2639 (01背包第k优解)

    /* 01背包第k优解问题 f[i][j][k] 前i个物品体积为j的第k优解 对于每次的ij状态 记下之前的两种状态 i-1 j-w[i] (选i) i-1 j (不选i) 分别k个 然后归并排序并 ...

随机推荐

  1. nagios 插件ndoutils 安装配置

    nagios 插件ndoutils 安装配置 原文地址:http://www.cnblogs.com/caoguo/p/5022645.html # Nagios install ndoutils # ...

  2. 安卓设置AttributeSet

    XmlPullParser parser = getResources().getXml(R.layout.textview);    AttributeSet attributes = Xml.as ...

  3. git 缓存密码导致的不能和远程仓库交互unable to access... 403错误

    尝试了各种方式,包括卸载等最终解决方案: 查看本机的credential 是否已经被清空. 如果输入了 git config credential.helper 命令之后没有输出,说明 git 的配置 ...

  4. bootstrap table 生成的表格里动态添加HTML元素按钮,JS中添加点击事件,点击没反应---解决办法

    bootstraptable中onExpandRow属性---js  方法添加的 html代码,然后给这代码里面的 元素 添加 事件,却获取不该元素.(称之为未来元素),由于是未来的 所以现在没有这个 ...

  5. PAT_A1018#Public Bike Management

    Source: PAT A1018 Public Bike Management (30 分) Description: There is a public bike service in Hangz ...

  6. java中关于数组的初始化

  7. JavaScript:一句代码输出重复字符串(字符串乘法)

    看到一个题目要求写一个函数times,输出str重复num次的字符串. 比如str:bac     num:3 输出:abcabcabc 除了利用循环还有几种方法,我学习研究之后记下以下三种方法. 1 ...

  8. Mac下对Android apk反编译

    在Mac上进行反编译apk,需要三个工具,分别为(附下载地址): apktool,下载Mac版 作用:资源文件获取,能够提取出图片文件和布局文件进行使用查看 dex2jar,下载最新的即可,目前是2. ...

  9. 使用androidstudio 分析内存泄漏

    分析内存泄漏 http://www.jianshu.com/p/c49f778e7acf

  10. GeoTrust 企业(OV)型 增强版(EV) SSL证书

      GeoTrust 企业(OV)型 增强版(EV) SSL证书(GeoTrust True BusinessID with EV SSL Certificates),验证域名所有权,更严格的验证企业 ...