hdoj2602

翻译 2012年03月28日 19:08:24

Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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

/* 
 * File:   main.cpp
 * Author: LeeningLu
 *
 * Created on 2012年3月27日, 下午3:01
 */

#include<stdio.h>
#include<memory.h>
#define M 1010

int T;

int N;//骨头数量
int V;//背包容量

struct bone{
    int value;//骨头价值
    int volume;//骨头所占背包容量
}bone[M];

int bag[M];

int main(void)
{
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&N,&V);//读取骨头数量和背包容量
        for(int i=1;i<=N;i++)
            scanf("%d",&bone[i].value);//读取每个骨头的价值
        for(int i=1;i<=N;i++)
            scanf("%d",&bone[i].volume);//读取每个骨头所占背包容量
        memset(bag,0,sizeof(bag));//初始化数组
        for(int j=1;j<=N;j++){
            for(int i=V;i>=0;i--){//背包从大到小开始搜索是因为,如果从小到大开始搜索,有时会把一块骨头重复搜索两次
                if(i>=bone[j].volume&&bone[j].value+bag[i-bone[j].volume]>bag[i])
                    //状态转移方程max{bone[j].value+bag[i-bone[j].volume],bag[i]}
            }
        }
        printf("%d\n",bag[V]);
    }
    return 0;
}





HDOJ2602

DP 问题;理解状态转移方程; #include #include #define MAX 1005 int D[MAX]; int max(int a, int b); int main(i...
  • Andrew_2014
  • Andrew_2014
  • 2014年07月29日 10:19
  • 255

hdoj2602 01背包

#include"iostream" #include"algorithm" using namespace std; const int volume=20000; const int num=20...
  • qq_32454729
  • qq_32454729
  • 2016年05月01日 13:14
  • 107

hdoj2602Bone Collector(01背包裸题)

Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Col...
  • z1192277815
  • z1192277815
  • 2016年08月11日 17:42
  • 175

动态规划 HDOJ2602-Bone Collector-01背包

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T...
  • chuchus
  • chuchus
  • 2015年09月23日 19:44
  • 535

Bone Collector(HDOJ2602)

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...
  • u011322198
  • u011322198
  • 2013年07月18日 15:50
  • 317

hdoj2602 Bone Collector

Problem Description  Many years ago , in Teddy’s hometown there was a man who was called “Bone Co...
  • minose
  • minose
  • 2017年02月18日 16:18
  • 103

HDOJ2602 bone collecter

0-1背包问题   #include"stdio.h" #include"string.h" #include"stdlib.h" #define MAX 1010 int f[MAX],...
  • whu_zxl
  • whu_zxl
  • 2012年02月11日 13:15
  • 260

HDOJ2602(DP0-1背包)

http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others...
  • lanjiangzhou
  • lanjiangzhou
  • 2013年05月30日 10:50
  • 480

HDOJ2602 Bone Collector

Bone Collector Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...
  • xing634325131
  • xing634325131
  • 2013年07月20日 23:59
  • 1166

hdoj2602 Bone Collector【dp 01背包】

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others...
  • R1986799047
  • R1986799047
  • 2015年07月28日 23:01
  • 339
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hdoj2602
举报原因:
原因补充:

(最多只允许输入30个字)