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. Leetcode0006--ZigZag Conversion

    [转载请注明]https://www.cnblogs.com/igoslly/p/9017638.html 来看一下题目: The string "PAYPALISHIRING" ...

  2. UICollectionView(一)基本概念

    整体预览 高等级的包含和管理(Top-level containment and management) UICollectionView UICollectionViewController UIC ...

  3. Discuz! G变量的使用方法

    1,G变量的使用方法: 例如:$_G['style'][boardlogo] 风格变量篇 $_G['style'] => Array (官方模板区 cr180整理 $_G['style'][st ...

  4. Java中面向对象三大特性之——多态

    多态的概述:  多态是继封装.继承之后,面向对象的第三大特性. 生活中,比如跑的动作,小猫.小狗和大象,跑起来是不一样的.再比如飞的动作,昆虫.鸟类和飞机,飞起来也是不一样的.可见,同一行为,通过不同 ...

  5. inline-block兼容IE7

    { display:inline-block; *display:inblock; *zoom:1 }

  6. chrome浏览器处理本地Ajax跨域

    chrome浏览器下 项目开发过程中,用到了Ajax异步请求.若将项目放在本地服务器中,通过localhost访问文件,不会报错.若直接通过file://访问文件就会报错. 报错信息: XMLHttp ...

  7. P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools

    P2746 [USACO5.3]校园网Network of Schools// POJ1236: Network of Schools 题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学 ...

  8. isinstance、issubclass、反射

    一.isinstance.issubclass # isinstance(obj, cls) 检查obj是否是cls的对象 class A(object):pass a = A() print(isi ...

  9. Windows环境下flask+Apache+mod_wsgi部署及爬坑

    文章目录 安装python Windows 环境使用virtualenv和virtualenvwrapper 安装mod_wsgi 安装nginx 安装Apache 遇到的坑 安装Apache遇到的坑 ...

  10. PAT 1094. The Largest Generation (层级遍历)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...