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(背包)的更多相关文章

  1. hdoj 2602 Bone Collector 【01背包】

    意甲冠军:给出的数量和袋骨骼的数,然后给每块骨骼的价格值和音量.寻求袋最多可容纳骨骼价格值 难度;这个问题是最基本的01背包称号,不知道的话,推荐看<背包9说话> AC by SWS 主题 ...

  2. hdoj - 2602 Bone Collector

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  3. Hdoj 2602.Bone Collector 题解

    Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...

  4. dp入门题目

    本文文旨,如题... 转载请注明出处... HDOJ 1176 免费馅饼 http://acm.hdu.edu.cn/showproblem.php?pid=1176 类似数塔,从底往上推,每次都是从 ...

  5. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  6. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  7. hdu 2602 Bone Collector 背包入门题

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

  8. [HDOJ 1171] Big Event in HDU 【完全背包】

    题目链接:HDOJ - 1171 题目大意 有 n 种物品,每种物品有一个大小和数量.要求将所有的物品分成两部分,使两部分的总大小尽量接近. 题目分析 令 Sum 为所有物品的大小总和.那么就是用给定 ...

  9. hdoj 2620 Bone Collector(0-1背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 思路分析:该问题为经典的0-1背包问题:假设状态dp[i][v]表示前i件物品恰放入一个容量为v ...

随机推荐

  1. House Robber II——Leetcode

    After robbing those houses on that street, the thief has found himself a new place for his thievery ...

  2. Bzoj 1696: [Usaco2007 Feb]Building A New Barn新牛舍 中位数,数学

    1696: [Usaco2007 Feb]Building A New Barn新牛舍 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 394  Solve ...

  3. JavaScript 概览 更新时间2014-0414-0837

    一些概念 DOM(文档对象模型)是HTML和XML的应用程序接口(API).DOM Level1规划文档结构:DOM Level2扩展了对鼠标和用户界面事件等的支持:DOM Level3支持了XML1 ...

  4. 在Openstack H版部署Nova Cell 时 ,终端输入nova service-list 和 nova host-list 命令将报错

    关于Cell的基本介绍,可以参考贤哥的一篇文章: [OpenStack]G版中关于Nova的Cell  http://blog.csdn.net/lynn_kong/article/details/8 ...

  5. 《Linear Algebra and Its Applications》-chaper3-行列式-克拉默法则

    计算线性方程组唯一解的克拉默法则:

  6. C++Primer第5版学习笔记(三)

    C++Primer第5版学习笔记(三) 第四/五章的重难点内容           你可以点击这里回顾第三章内容       因为第五章的内容比较少,因此和第四章的笔记内容合并.       第四章是 ...

  7. Subversion/Git/ReviewBoard工作流程

    根据My (work)Git Workflow进行修改,在 Windows下进行测试,http://mojodna.net/2009/02/24/my-work-git-workflow.html 目 ...

  8. cmd的copy命令合并多个文件

    1.1个a.jpg文件:1个b.php文件(一句话木马)

  9. [IOS开发进阶与实战]第一天:CoreData的运行机制

    1.数据模型NSManagedObjectModel的建立 1.- (NSManagedObjectModel *)managedObjectModel { if (_managedObjectMod ...

  10. 一个可视化的retrospective网站

    IdeaBoardz - Brainstorm, Retrospect, Collaborate是一个可视化的retrospective,brainstorm的网站,比较简单易用,可以导出pdf和ex ...