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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • IDEA下Log4j使用教程

    IDEA下Log4j使用教程 2015年12月14日15:30:21阅读数:13467Log4j是Apache的一个开源项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台、文件、GUI组件,甚至是套接口服务器、NT的事件记录器、UNIXSyslog守护进程等;我们也可以控制每一条日志的输出格式;通过定义每一条日志信息的级别,我们能够更加细致地控制日志的生成过程。最令人感兴趣的就是,这些…

    2025年9月14日
    5
  • 此视频无法播放0xc00d36c4_视频播放失败代码-30

    此视频无法播放0xc00d36c4_视频播放失败代码-30相信很多用户都遇到过视频无法播放的问题。比如将重要视频从旧电脑拷到U盘上,使用另一台电脑播放时,提示视频播放错误代码0xc00d36c4,不支持该视频播放。其实,视频无法播放的问题是很常见的,不少用户在电脑上连接相机或者手机后播放视频,也会提示0xc00d36c4。出现这样的问题要怎么解决,怎么才能修复该视频文件使其正常播放?播放MP4格式视频显示错误代码0xc00d36c4的情况大多数情况下,…

    2022年9月29日
    3
  • iframe属性

     iframe:在网页里设置一个子窗口            target="_blank"额外跳转一个网页            target="_top" 当前网页跳转            target标签取消的话 子网页跳转            target="name属性" 在name…

    2022年4月5日
    55
  • oracle数据库添加用户至dba_oracle取消用户dba权限

    oracle数据库添加用户至dba_oracle取消用户dba权限首先用管理员身份进入数据库SQLPLUSSYSTEM/密码sqlplussystem/diwaycom创建用户CREATEUSER用户名IDENTIFIEDBY密码;createuserdiwayidentifiedbydiwaycom;将刚创建的用户解锁ALTERUSER用户名ACCOUNTUNLOCK/LOCK;Alteruserdiwayaccount…

    2022年9月26日
    2
  • 施密特正交化几何解释

    施密特正交化几何解释施密特正交化几何解释

    2022年4月24日
    61
  • 国标 计算机机房,国标相关知识:电子信息系统机房设计规范(GB50174-2008)[通俗易懂]

    国标 计算机机房,国标相关知识:电子信息系统机房设计规范(GB50174-2008)[通俗易懂]1总则1.0.1为规范电子信息系统机房设计,确保电子信息系统安全、稳定、可靠地运行,做到技术先进、经济合理、安全适用、节能环保,制定本规范。1.0.2本规范适用于建筑中新建、改建和扩建的电子信息系统机房的设计。1.0.3电子信息系统机房的设计应遵循近期建设规模与远期发展规划协调一致的原则。1.0.4电子信息系统机房设计除应符合本规范外,尚应符合国家现行有关标准、规范的规定。2术语2.0.1电子信息…

    2022年10月2日
    5

发表回复

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

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