Bone Collector-HDU
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 ?
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.
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
long long max(long long num1,long long num2)//比较函数
{
return num1>num2?num1:num2;
}
long long dp[][];//定义背包数组
int main()
{
int t;//数据组数
int m_bone,m_volume;
int bone[], volume[];
cin >> t;
while (t--)
{
int i, j, k;
memset(dp, , sizeof(dp));//初始化
memset(bone,,sizeof(bone));
memset(volume, , sizeof(volume));
cin >> m_bone >> m_volume;//输入骨头总数和容量
for (i = ; i <= m_bone; i++)
cin >> bone[i];//输入价值
for (j = ; j <= m_bone; j++)
cin >> volume[j];//输入容量
for (i = ; i <= m_bone; i++)
{
for (j = ; j <= m_volume; j++)
{
if (j < volume[i])//如果装不下
{
dp[i][j] = dp[i - ][j];//将上一个值赋给当前的价值
continue;
}
else
{
dp[i][j] = max(dp[i - ][j], dp[i - ][j - volume[i]] + bone[i]);//动态转移方程
}
}
}
cout << dp[m_bone][m_volume] << endl;//输出价值最大
}
return ;
}
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
long long max(long long num1,long long num2)//比较函数
{
return num1>num2?num1:num2;
}
long long dp[];//定义背包数组
int main()
{
int N;
int i,j,k;
int bone[];//定义价值
int volume[];//定义容量
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));//初始化
int count,weight;
scanf("%d%d",&count,&weight);//输入组数和总重量
for(j=;j<=count;j++)
scanf("%d",&bone[j]);
for(j=;j<=count;j++)
scanf("%d",&volume[j]);
for(i=;i<=count;i++)
{
for(k=weight;k>=;k--)
{
if(k-volume[i]<)//装不下
{
break;
}
else
dp[k]=max(dp[k-volume[i]]+bone[i],dp[k]);
cout << dp[k] << endl;
}
}
printf("%lld\n",dp[weight]);
}
return ;
}
Bone Collector-HDU的更多相关文章
- bone collector hdu 01背包问题
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- 背包!背包!HDU 2602 Bone Collector + HDU 1114 Piggy-Bank + HDU 2191 512
http://acm.hdu.edu.cn/showproblem.php?pid=2602 第一题 01背包问题 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 3639 Bone Collector II(01背包第K优解)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 2602 Bone Collector (简单01背包)
Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...
- hdu 2602 Bone Collector 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...
- hdu 2639 Bone Collector II
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- Bone Collector II(HDU 2639 DP)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 【01背包】HDU 2602 Bone Collector (模板题)
Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...
随机推荐
- 【转】Linux设备驱动--块设备(一)之概念和框架
原文地址:Linux设备驱动--块设备(一)之概念和框架 基本概念 块设备(blockdevice) --- 是一种具有一定结构的随机存取设备,对这种设备的读写是按块进行的,他使用缓冲区来存放暂时 ...
- JAVA To C++ Converter Cracked ( 破解版 )
JAVA To C++ Converter v17.10.2 Cracked by X-Cracker 简介 JAVA To C++是一款将JAVA代码或项目转换为 C++的工具 免费版本只每次只支持 ...
- LINUX 笔记-date命令
显示当前时间: 命令: focus@ubuntu:~$ date Thu Aug 31 03:01:17 PDT 2017 focus@ubuntu:~$ date '+%x' 08/31/2017 ...
- 【ASP.NET MVC 学习笔记】- 09 Area的使用
本文参考:http://www.cnblogs.com/willick/p/3331519.html 1.ASP.NET MVC允许使用 Area(区域)来组织Web应用程序,这对于大的工程非常有用, ...
- 使用Git与Github创建自己的远程仓库
原因 早就想创建一个自己的远程仓库,方便发布到Nuget上,自己用也好,项目组用也好,都方便. 今天抽了个时间建了个仓库,随便记下溜方便后来的人. 流程 1,创建自己的GitHub仓库 首先需要到 G ...
- javascript 之作用域-06
作用域 作用域是指变量和函数可访问范围,他规定了如何查找变量,也就是确定当前执行代码对变量的访问权限. 作用域有两种工作模式: 静态作用域 :又称为词法作用域,在编译阶就可以决定变量的引用,由程序定义 ...
- LeetCode 18. 4Sum (四数之和)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- HandlerThread学习
之前基本讲过Handler的一些知识了,我们今天学习下Google封装的一个实现线程通信的一个类HandlerThread 一.HandlerThread使用 @Override protected ...
- SQL基本查询_单表查询(实验二)
SQL基本查询_单表查询(实验二) 查询目标表结构及数据 emp empno ename job hiedate sal comn deptno 1007 马明 内勤 1992-6-12 4000 2 ...
- @RequestBody对象为空,异常Required request body is missing
1.异常 org.springframework.http.converter.HttpMessageNotReadableException: Required request body is mi ...