码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • HDU 2602: Bone Collector ← 0-1背包问题


    【题目来源】
    http://acm.hdu.edu.cn/showproblem.php?pid=2602

    【题目描述】
    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 ?

    【数据输入】
    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.

    【数据输出】
    One integer per line representing the maximum of the total value (this number will be less than 2^31).


    【算法代码】

    1. #include
    2. using namespace std;
    3. const int maxn=1005;
    4. int c[maxn][maxn];
    5. int val[maxn],vol[maxn];
    6. int main(){
    7. int t,N,V;
    8. cin>>t;
    9. while(t--){
    10. cin>>N>>V;
    11. for(int i=1;i<=N;i++)
    12. cin>>val[i];
    13. for(int i=1;i<=N;i++)
    14. cin>>vol[i];
    15. for(int i=0;i<=N;i++)
    16. c[i][0]=0;
    17. for(int j=0;j<=V;j++)
    18. c[0][j]=0;
    19. for(int i=1;i<=N;i++)
    20. for(int j=0;j<=V;j++)
    21. if(j-1][j];
    22. else c[i][j]=max(c[i-1][j],c[i-1][j-vol[i]]+val[i]);
    23. cout<
    24. }
    25. return 0;
    26. }
    27. /*
    28. in:
    29. 1
    30. 5 10
    31. 1 2 3 4 5
    32. 5 4 3 2 1
    33. out:
    34. 14
    35. */



    【参考文献】
    https://blog.csdn.net/hnjzsyjyj/article/details/126067759
    https://blog.csdn.net/hnjzsyjyj/article/details/125944790

     

  • 相关阅读:
    Sublime Text 4 for Mac激活下载
    【JavaScript-进阶】详解数据类型,内存分配,API元素对象获取
    刨根问底 Redis, 面试过程真好使
    Python爬虫提高排名
    WPS前骨干历时10年打造新型软件,Excel用户:我为此改用WPS
    Linux安装与配置SSH服务
    猿创征文丨赶紧进来!!! 详细介绍C语言指针(九千字完结篇)
    vue项目开发环境工具-node
    智能优化之遗传算法
    在浏览器上输入一个网址后,发生了什么?
  • 原文地址:https://blog.csdn.net/hnjzsyjyj/article/details/126068086
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号