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 ...
随机推荐
- ReactNative学习笔记(七)Navigator的使用
前言 Navigator主要用于ReactNative中的跳转,中文文档: http://reactnative.cn/docs/0.39/using-navigators.html 懒得打字介绍更多 ...
- 背水一战 Windows 10 (87) - 文件系统: 获取文件的属性, 修改文件的属性, 获取文件的缩略图
[源码下载] 背水一战 Windows 10 (87) - 文件系统: 获取文件的属性, 修改文件的属性, 获取文件的缩略图 作者:webabcd 介绍背水一战 Windows 10 之 文件系统 获 ...
- 对 UDP 的一些思考
先放两个链接 快速可靠协议-KCP 可靠 UDP 传输 最近在玩王者荣耀,发觉两件事: 1. 可以 4G 和 wifi 无痛切换 2. 当网络不好的时候,发出去的消息并不保证到达服务器.比如你在很卡的 ...
- Fetch的使用及兼容ie的处理
Fetch 作为一个与时俱进的前端,Fetch当然应该有所了解和涉猎.如果你没有听说过Fetch,那么ajax应该不陌生吧.Fetch相当于是一个新版本的Ajax,虽然现在我们常常使用的仍是ajax, ...
- redis 缓存
本篇博客只介绍 redis 作为缓存的的一些使用,以及在项目中如何把redis和spring如何集成. 1:redis的maven依赖,redis 依赖 spring-redis 依赖: < ...
- 第二篇:服务消费者(RestTemplate+ribbon)
第一篇讲了服务的注册,这篇来说说服务的调用,服务与服务的通讯是基于http restful,springcloud的服务调用是通过ribbon方式的,客户端的负载均衡. Talk is cheap.S ...
- Telerik for AJAX RadGrid控件
作为一名.net小白,今天分享一下telerik知识的学习.熟悉ASP.NET Web Form的都知道Grid View或者是List View等表格控件,所以今天和大家分享一下telerik Ra ...
- 从CSR产品名录看公司发展历程和业务方向
产品型号 主要功能 BC3系列(例BC31A223, ...
- 机器学习基石笔记:08 Noise and Error
噪声:误标.对同一数据点的标注不一致.数据点信息不准确...... 噪声是针对整个输入空间的. 存在噪声的情况下,VC bound依旧有用: 存在噪声,就是f------>p(y|x),f是p的 ...
- Win10手记-IIS部署网站问题解决
最近在自己的Win10电脑上尝试部署ASP.NET网站时出现了问题,经过多方查找定位到IIS为问题来源. 开始之前 先描述下技术环境: 1.Windows 10 PC 2.Windows 自带的IIS ...