hdoj 2602(背包)
Problem D
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 9 Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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
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
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14 代码:
#include<stdio.h>
#include<string.h>
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int t,n,m,a[10001],b[10001],dp[10001],i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
{
for(j=m;j>=b[i];j--)
{
dp[j]=max(dp[j],dp[j-b[i]]+a[i]);
}
}
printf("%d\n",dp[m]);
}
return 0;
}
hdoj 2602(背包)的更多相关文章
- hdoj 2602 Bone Collector 【01背包】
意甲冠军:给出的数量和袋骨骼的数,然后给每块骨骼的价格值和音量.寻求袋最多可容纳骨骼价格值 难度;这个问题是最基本的01背包称号,不知道的话,推荐看<背包9说话> AC by SWS 主题 ...
- hdoj - 2602 Bone Collector
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Hdoj 2602.Bone Collector 题解
Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...
- dp入门题目
本文文旨,如题... 转载请注明出处... HDOJ 1176 免费馅饼 http://acm.hdu.edu.cn/showproblem.php?pid=1176 类似数塔,从底往上推,每次都是从 ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- 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 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...
- [HDOJ 1171] Big Event in HDU 【完全背包】
题目链接:HDOJ - 1171 题目大意 有 n 种物品,每种物品有一个大小和数量.要求将所有的物品分成两部分,使两部分的总大小尽量接近. 题目分析 令 Sum 为所有物品的大小总和.那么就是用给定 ...
- hdoj 2620 Bone Collector(0-1背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 思路分析:该问题为经典的0-1背包问题:假设状态dp[i][v]表示前i件物品恰放入一个容量为v ...
随机推荐
- HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
Fraction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- Microsoft JScript 运行时错误: Automation 服务器不能创建对象
var WshShell = new ActiveXObject('WScript.Shell') WshShell.SendKeys( '{F11}'); 问题: ...
- unicode随笔小计
科普字符集: ascii:一个字节,占8位,(0000 0000 - 1111 1111) 如果只是英语那就没什么问题. 后来,不同的语言有了编码诞生.为了统一,出现一个大集合.便有了. unicod ...
- 文件夹oradiag_是如何产生的
如果sqlnet.ora不可用或者ADR_BASE参数未定义,那么11g的 SQL*Net将创建这些文件夹 (详情:http://download.oracle.com/docs/cd/B28359_ ...
- [JIT_APP]Android SQLite简介
SQLite介绍 SQLite是一个非常流行的嵌入式数据库,它支持SQL语言,并且只利用很少的内存就有很好的性能.此外它还是开源的,任何人都可以使用它.许多开源项目(Mozilla, PHP, Pyt ...
- ACM1997_汉诺栽塔VII
#include <stdio.h> #include <iostream> #include <queue> #include <stdlib.h> ...
- 如何以非 root 用户将应用绑定到 80 端口-ssh 篇 » 社区 » Ruby China
如何以非 root 用户将应用绑定到 80 端口-ssh 篇 » 社区 » Ruby China 如何以非 root 用户将应用绑定到 80 端口-ssh 篇
- Java中json工具对比分析
Java中几个json工具分析 1, 环境 JDK1.6+IDE(IntelliJ IDEA)+windowsXP+GBK编码 2,分析对象 jackson1.8.2 http://jackson.c ...
- AE 线编辑
转自原文 AE 线编辑 1.高亮显示节点 //高亮显示节点和端点 public void HighLightNode() { //清空 _mapCtrl.Map.ClearSelection(); _ ...
- [NOIP2015pj题解]From某因为时间快了那么一点点超过下一位的蒟蒻(其实是纯代码).
第一题,很水,直接上代码 #include <iostream> #include <fstream> #include <cstdlib> /* run this ...