hdu 2602 - Bone Collector(01背包)解题报告
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 39532 Accepted Submission(s): 16385
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 ?

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.
1
5 10
1 2 3 4 5
5 4 3 2 1
14
题解:
裸的01背包,经典例题。
參考代码:
#include<stdio.h>
#define M 1111
#include<string.h>
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int t,a[M],b[M],dp[M];
scanf("%d",&t);
while(t--)
{
int n,v;
memset(dp,0,sizeof(dp));
scanf("%d%d",&n,&v);
for(int i=0;i<n;i++)
scanf("%d",&b[i]);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
for(int j=v;j>=a[i];j--)
{
dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
}
}
printf("%d\n",dp[v]);
}
return 0;
}
hdu 2602 - Bone Collector(01背包)解题报告的更多相关文章
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
- HDU 2602 Bone Collector --01背包
这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include < ...
- HDU 2602 Bone Collector (01背包DP)
题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...
- [HDU 2602]Bone Collector ( 0-1背包水题 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...
- HDU 2602 Bone Collector (01背包问题)
原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many yea ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2602 Bone Collector(经典01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...
随机推荐
- Codeforces Round #440(Div.2)
一句话题意: A:给出两个长为\(n\),\(m\)的的数组,每个数在\(1\)到\(9\)之间,求出一个最小的数使得至少有一位出现在一个数组中,且至少有一位出现在另一个数组中.\(n,m\leq9\ ...
- leetcode 21 list merge
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...
- JavaScript 笔记(7) -- 在HTML中嵌入 js (外部引用)
本节主要说明,在HTML中嵌入自定义 JavaScript.通过HTML的script标签加载JavaScript文件 为防止网页加载缓慢,也可以把非关键的JavaScript放到网页底部,例如下面的 ...
- JavaScript (JS)基础:ECMAScript 浅析 (含Math基本方法解析)
浏览器端JavaScript的组成 ECMAScript:语法规范 DOM:Document Object Model 文档对象模型,操作页面元素 BOM:Browser Object Model ...
- [LeetCode] Gas Station 贪心
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- MMU介绍【转】
转自:http://blog.csdn.net/martree/article/details/3321578 虚拟存储器的基本思想是程序,数据,堆栈的总的大小可以超过物理存储器的大小,操作系统把当前 ...
- C#图解教程学习笔记——类和继承
一.屏蔽基类的成员所有类都派生自object类.虽然类只能直接继承一个基类,但继承的层次没有限制.虽然派生类不能删除它继承的任何成员,但可以用与基类同名的成员来屏蔽(mask)基类成员.1. 要屏蔽一 ...
- Django之model F/Q以及多对多操作
model之F/Q操作 F操作,使用查询条件的值 打个比方吧,有一张表,保存着公司员工的工资,公司普涨工资,如何在model中操作,这就用到了F,首先需要导入此模块: from django.db.m ...
- web前端生成图片之探索踩坑
前段时间,产品和运营整了个非常变态的需求,要求将一个活动页面输出为图片,然后用户进行分享 开始以为是用户自己手动截图分享,没想到后来不是,细思极恐,感叹需求之变态. 从网上找了N个方案,最后确定使用 ...
- win10下安装redis
Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases Redis 支持 32 位和 64 位.这个需要根据你系统平台的实际情况选择, ...