HDU5887(SummerTrainingDay01-D)
Herbs Gathering
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1470 Accepted Submission(s): 366
Problem Description
Input
For each case, the first line consists two integers, the total number of different herbs and the time limit.
The i-th line of the following n line consists two non-negative integers. The first one is the time we need to gather and prepare the i-th herb, and the second one is its score.
The total number of different herbs should be no more than 100. All of the other numbers read in are uniform random and should not be more than 109.
Output
Sample Input
Sample Output
Source
//2017-10-08
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long using namespace std; const int N = ; int n;
struct Bag{
ll v, w;
bool operator<(const Bag x) const {
return v*x.w > w*x.v;
}
}bag[N]; ll ans, limit;
void dfs(int step, ll wight, ll value){
if(wight > limit)return;
if(value > ans)ans = value;
if(step >= n)return;
if(value*1.0 + bag[step].v*1.0/(bag[step].w*1.0)*(limit-wight) <= ans*1.0)
return;//如果以当前最高的性价比装满剩下的容量,所得价值都不如当前最优解,则剪枝。
dfs(step+, wight+bag[step].w, value+bag[step].v);
dfs(step+, wight, value);
} int main()
{
while(~scanf("%d%lld", &n, &limit)){
for(int i = ; i < n; i++){
scanf("%lld%lld", &bag[i].w, &bag[i].v);
}
sort(bag, bag+n);
ans = ;
dfs(, , );
printf("%lld\n", ans);
} return ;
}
HDU5887(SummerTrainingDay01-D)的更多相关文章
- HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)
背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...
- hdu5887 Herbs Gathering
神他妈随便写写就能过- 暴力枚举每个取不取 两个剪纸: 1.当剩下可用的时间小于最少需要用的时间 跳出 2.当剩下的植物按照理想情况(甚至可以取一部分)得到的极限答案比已经求出的答案大 跳出 #inc ...
随机推荐
- DRF 商城项目 - 日志处理
logging 模块 logging 模块是最基本的日志处理模块 缺陷 但是拥有一些很致命的缺陷 要求用户主动查询, 需要登录到服务器才可以查看日志文件 自带的报错外部通知也没办法判断同类取舍, 短 ...
- Javascript高级编程学习笔记(4)—— JS中的数据类型(2)
接着昨天的文章,今天这篇文章主要讲述JS中剩余的两种数据类型String,和Object String类型 对于该类型,书中给出的解释为:由0或多个16为Unicode字符组成的字符序列. 对于JS中 ...
- Android网络请求与数据解析,使用Gson和GsonFormat解析复杂Json数据
版权声明:未经博主允许不得转载 一:简介 [达叔有道]软件技术人员,时代作者,从 Android 到全栈之路,我相信你也可以!阅读他的文章,会上瘾!You and me, we are family ...
- GraphQL:你的容颜,十万光年
What? GraphQL 是一种类似于 SQL 的结构化查询语言,由 facebook 于2012年创造,于2015年开源.SQL 在服务端定义,GraphQL 在客户端定义,也就是说 GraphQ ...
- Qt之实现网络下发配置的半透明友好提示界面
一.说明 在使用Qt开发的网管客户端程序中,网管客户端主要负责显示设备信息以及对设备下发配置信息等,如配置设备名字.更新设备程序等:由于在网管客户端程序的操作要先经过服务器处理,再由服务器将该命令转发 ...
- HoloLens开发手记 - HoloLens shell概述 HoloLens shell overview
使用HoloLens时,shell是由你周围的世界和来自系统的全息图像构成.我们将这种空间成为混合世界(mixed world). shell包含了一个可以让你将全息图像和应用放置在世界中的开始菜单( ...
- 在Windows环境中安装Neo4j
图形数据库(Graph Database)是NoSQL数据库家族中特殊的存在,用于存储丰富的关系数据,Neo4j 是目前最流行的图形数据库,支持完整的事务,在属性图中,图是由顶点(Vertex),边( ...
- Volley Post网络请求
/*post请求*/public void dostringVolleypost(){ /*第一步,创建请求队列*/ queue = Volley.newRequestQueue(this); /*第 ...
- Android_自适应布局
1.屏幕相关概念1.1分辨率是指屏幕上有横竖各有多少个像素1.2屏幕尺寸指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸android将屏幕大小分为四个级别(smal ...
- 私服仓库 nexus 环境搭建(win10)
1.1 简介: Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven中央仓库 下载所需要的构件(artifact),但这通常不是一个好的做法,你应该在本地架设一个Maven仓库 ...