hdoj 2602(背包)

Problem D

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 9   Accepted Submission(s) : 6

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

代码:

#include<stdio.h>
#include<string.h>

int max(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    int t,n,m,a[10001],b[10001],dp[10001],i,j;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=0;i<n;i++)
        {
            scanf("%d",&b[i]);
        }
        memset(dp,0,sizeof(dp));
        for(i=0;i<n;i++)
        {
            for(j=m;j>=b[i];j--)
            {
                dp[j]=max(dp[j],dp[j-b[i]]+a[i]);
            }
        }
        printf("%d\n",dp[m]);
    }
    return 0;
}

hdoj 2602(背包)

时间: 2024-10-12 06:53:58

hdoj 2602(背包)的相关文章

hdoj 2602 Bone Collector 【01背包】

意甲冠军:给出的数量和袋骨骼的数,然后给每块骨骼的价格值和音量.寻求袋最多可容纳骨骼价格值 难度;这个问题是最基本的01背包称号,不知道的话,推荐看<背包9说话> AC by SWS 主题链接 http://acm.hdu.edu.cn/showproblem.php?pid=2602 代码: #include<stdio.h> #include<string.h> typedef struct{ int w, v; }str; str s[1005]; int dp[

HDOJ 2602 Bone Collector【01背包】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 34251    Accepted Submission(s): 14101 Problem Description Many years ago , in

HDOJ 2602 Bone Collector--01背包

题目来源:HPU 2602--Bone Collector Problem Description Manyyears ago , in Teddy's hometown there was a man who was called "BoneCollector". This man like to collect varies of bones , such as dog's , cow's ,also he went to the grave - The bone collecto

hdoj 2602 Bone Collector【0-1背包】【dp思想】

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40247    Accepted Submission(s): 16722 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

HDOJ 2602 Bone Collector 【动态规划】

题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17434 动态规划: 经典的01背包问题 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].    求解将哪些物品装入背包可使价值总和最大. 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放.    用子问题定义状态:即f[i][v]表示前i件物品恰放入一个容量为v的背包可以获得的最大价值.则其状态转移方程便是:     

dp入门题目

本文文旨,如题... 转载请注明出处... HDOJ 1176 免费馅饼 http://acm.hdu.edu.cn/showproblem.php?pid=1176 类似数塔,从底往上推,每次都是从下面三个中选最大的 1 #include<cstdio> 2 #include<cstring> 3 #define MAXN 100005 4 int dp[MAXN][11];//第i秒第j个位置的馅饼数 5 int max1(int a,int b) 6 { 7 return a

DP题目

//HDU 4001 To Miss Our Children Time HDU 4433 locker HDU 4362 Dragon Ball[] HDU 3602 2012[] HDU 4385 Moving Bricks[] HLG 1067 QQ Farm[] HDU 4293 Groups HDU 3920 Clear All of Them I[] HDU 3466 Proud Merchants[] POJ 2923 Relocation[] HDU 3660 Alice and

hdoj 1203 I NEED A OFFER! 【另类01背包】【概率背包】

题意:... 策略:动态规划. 因为是求至少能得到一个offer的概率,那我们可以反着求,求得不到一个offer的概率,最后用1减去就好了. 代码: #include<string.h> #include<stdio.h> double dp[10010]; struct node{ int a; double b; }s[10010]; int main() { int n, m, i, j; while(scanf("%d%d", &n, &

背包DP HDOJ 5410 CRB and His Birthday

题目传送门 题意:有n个商店,有m金钱,一个商店买x件商品需要x*w[i]的金钱,得到a[i] * x + b[i]件商品(x > 0),问最多能买到多少件商品 01背包+完全背包:首先x == 1时,得到a[i] + b[i],若再买得到的是a[i],那么x == 1的情况用01背包思想,x > 1时就是在01的基础上的完全背包.背包dp没刷过专题,这么简单的题也做不出来:( /************************************************* Author