Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 46460    Accepted Submission(s): 19338

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

发现不做DP不行啊,以后还怎么混。先来道题入个门....

代码:

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
struct gutou
{
int val;
int weigh;
}bone[1010];
int dp[1010][1010];
int main (void)
{
int t,i,n,j,v;
cin>>t;
while (t--)
{
memset(dp,0,sizeof(dp));
cin>>n>>v;
for (i=1; i<=n; i++)
{
cin>>bone[i].val;
}
for (i=1; i<=n; i++)
{
cin>>bone[i].weigh;
}
for (i=1; i<=n; i++)
{
for (j=v; j>=0; j--)
{
if(j<bone[i].weigh)//二维的话必须要有这局
{
dp[i][j]=dp[i-1][j];
continue;
}
dp[i][j]=max( dp[i-1][j] , dp[i-1][j-bone[i].weigh]+bone[i].val );//取和不取
}
}
cout<<dp[n][v]<<endl;
}
return 0;
}

HDU——2602Bone Collector(01背包)的更多相关文章

  1. ACM HDU Bone Collector 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有 ...

  2. HDU 2602Bone Collector 01背包问题

    题意:给出一个t代表有t组数据,然后给出n,n代表有n种石头,v代表旅行者的背包容量,然后给出n种石头的价值和容量大小,求能带走的最大价值 思路:01背包问题,每种石头只有拿与不拿两种状态.(其实我是 ...

  3. hdu 2546 典型01背包

    分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意 ...

  4. HDU 2602 Bone Collector(01背包裸题)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. HDU 2602 - Bone Collector - [01背包模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...

  6. HDU 2602 Bone Collector --01背包

    这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include < ...

  7. HDU 2602 Bone Collector (01背包DP)

    题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...

  8. HDU 2639(01背包求第K大值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Jav ...

  9. Bone Collector(01背包+记忆化搜索)

    Bone Collector Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  10. hdu 2955 Robberies (01背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...

随机推荐

  1. Sublime +Markdown+OmniMarkupPreviewer 搭建实时预览的markdown编辑器

    浏览器实时预览 <meta http-equiv="refresh" content="0.1"> auto save 的配置 {"aut ...

  2. fastjson中转字符串时格式化、显示null值等

    fastjson中object转string时的配置项,包括 1. 是否显示value为null的项 2. 是否格式化显示字符串 3. 日期是否格式化显示为可读字符串 ... 这些的配置均在Seria ...

  3. docker单主机网络

    当你安装Docker时,它会自动创建三个网络.你可以使用以下docker network ls命令列出这些网络: [root@localhost ~]# docker network ls NETWO ...

  4. 虚IP切换原理

    高可用性HA(High Availability)指的是通过尽量缩短因日常维护操作(计划)和突发的系统崩溃(非计划)所导致的停机时间,以提高系统和应用的可用性.HA系统是目前企业防止核心计算机系统因故 ...

  5. python之文件操作的初识

    1. 操作文件 1.1 操作的方法 f = open("文件路径",mode="模式",encoding="编码") open() # 调用 ...

  6. java,求1-100以内所有偶数的和。

    package study01; public class Even { public static void main(String[] args) { int sum = 0; for (int ...

  7. 设置通过Maven创建的工程的JDK的版本,更改conf/settings.xml

    eclipse提示警告如下: Build path specifies execution environment J2SE-1.5. There are no JREs installed in t ...

  8. Docker 镜像&仓库 获取及推送镜像

    docker查看.删除镜像 docker镜像存储位置: /var/lib/docker 查看docker信息也可以查看保存位置 docker info 1.列出镜像 docker images -aa ...

  9. 我如何解决Centos下cannot find a valid baseurl for repo的问题的

    刚刚安装完centos,进入命令行模式后,发现所有的命令都不能使用,最后一行显示:Error:Cannot find a valid baseurl for repo:base,如何解决? 在cent ...

  10. centos7安装pgsql及操作命令

    1.下载所需要的数据库版本https://yum.postgresql.org/repopackages.php 2.安装数据库版本包 yum install -y https://download. ...