HDU2602 Bone Collector 【01背包】[通俗易懂]

HDU2602 Bone Collector 【01背包】

大家好,又见面了,我是全栈君。

Bone Collector

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

Total Submission(s): 28365    Accepted Submission(s): 11562
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 ?


HDU2602 Bone Collector 【01背包】[通俗易懂]


 

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 2
31).
 

Sample Input
   
   
1 5 10 1 2 3 4 5 5 4 3 2 1

 

Sample Output
   
   
14

01背包入门题。

#include <stdio.h>
#include <string.h>
#define maxn 1002

int dp[maxn], w[maxn], v[maxn];

int main()
{
    int t, n, val, i, j;
    scanf("%d", &t);
    while(t--){
        scanf("%d%d", &n, &val);
        for(i = 1; i <= n; ++i) scanf("%d", v + i);
        for(i = 1; i <= n; ++i) scanf("%d", w + i);
        memset(dp, 0, sizeof(dp));
        for(i = 1; i <= n; ++i){
            for(j = val; j >= w[i]; --j){
                if(dp[j] < dp[j-w[i]] + v[i]) 
                    dp[j] = dp[j-w[i]] + v[i];
            }
        }
        printf("%d\n", dp[val]);
    }
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116407.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • adb命令修改手机分辨率_adb命令查看安卓版本

    adb命令修改手机分辨率_adb命令查看安卓版本打开所要查看的应用包名:$adbshelldumpsysactivitytop|head-n10TASKcom.ss.android.article.newsid=5ACTIVITYcom.ss.android.article.news/com.ss.android.article.base.activity.DetailActivity4407b468pid=2714…

    2022年8月13日
    0
  • Django(64)频率认证源码分析与自定义频率认证[通俗易懂]

    Django(64)频率认证源码分析与自定义频率认证[通俗易懂]前言有时候我们发送手机验证码,会发现1分钟只能发送1次,这是做了频率限制,限制的时间次数,都由开发者自己决定频率认证源码分析defcheck_throttles(self,request):

    2022年7月31日
    11
  • VMWare的P2V、V2V使用「建议收藏」

    VMWare的P2V、V2V使用「建议收藏」1.测试环境2.软件安装双击安装文件,依次点击”下一步”,如下图:3.软件参数修改4.将物理机(192.168.80.103)转换到ESXI(192.168.80.102)在Windows10中安装vCenterConverter6转换软件,将WindowsServer2008R2或WindowsServer2012R2转换到ESXI主机。转换前注意事项:登录到…

    2022年7月14日
    18
  • cortex-m3权威指南_core M3

    cortex-m3权威指南_core M3Cortex-M3Bit-Banding1.概述CM3的存储器系统支持所谓的“位带”(bit-band)操作。通过它,实现了对单一bit的原子操作。位带操作仅适用于一些特殊的存储器区域中。从汇编角度看:与传统方法的比较:在位带区中,每个比特都映射到别名地址区的一个字——这是个只有LSB才有效的字。支持位带操作的两个内存区的范围是:0x2000_0000-0x2…

    2022年10月13日
    0
  • 2020年3月23日阿里笔试题[通俗易懂]

    2020年3月23日阿里笔试题[通俗易懂]2020年3月23日阿里笔试题题目描述题目分析  这是阿里的第二场笔试,本来觉得没啥好写的,一道排列组合,一道迷宫。没有什么发挥的空间。但是后来在和大家讨论的过程中,把这道题的公司给敲出来了,但是这公式也不能白敲,干脆写一篇文章总结一下。题目描述一共n个人,从中选出任意个人组成一队,我们不妨记为k,再从k个人选出一人做队长。题目分析  这是一个典型的排列组合问题,从n个人选出k个,可…

    2022年5月22日
    26
  • 洛谷P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

    洛谷P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

    2021年9月17日
    47

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号