hdu5887 Herbs Gathering
神他妈随便写写就能过…
暴力枚举每个取不取
两个剪纸:
1.当剩下可用的时间小于最少需要用的时间 跳出
2.当剩下的植物按照理想情况(甚至可以取一部分)得到的极限答案比已经求出的答案大 跳出
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
typedef long long ll;
struct Node{
ll a,b;
}p[105];
int cmp(Node x,Node y) {
ll t1 = 1ll*x.b*y.a; ll t2 = 1ll*x.a*y.b;
return t1 > t2;
}
ll N,M;
ll ans;
ll minpay;
void dfs(int x,ll pay,ll gain) {
if(minpay > M-pay || x == N+1) {
ans = max(ans, gain);
return;
}
ll P = pay; ll G = gain;
for(int i = x; i <= N; ++i) {
if(P+p[i].a <= M) P += p[i].a, G += p[i].b;
else { G += (M-P)*p[i].b/p[i].a+1; break; }
}
if(G <= ans) return;
dfs(x+1,pay,gain);
if(pay+p[x].a <= M) dfs(x+1, pay+p[x].a, gain+p[x].b);
}
int main(){
while(~scanf("%lld %lld",&N,&M)) {
minpay = INF;
for(int i = 1; i <= N; ++i) {
scanf("%lld %lld",&p[i].a, &p[i].b);
minpay = min(minpay, p[i].a);
}
sort(p+1,p+N+1,cmp);
ans = 0;
dfs(2,0,0);
if(p[1].a <= M) dfs(2,p[1].a,p[1].b);
printf("%lld\n",ans);
}
return 0;
}
hdu5887 Herbs Gathering的更多相关文章
- HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)
背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...
- HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)
Herbs Gathering 10.76% 1000ms 32768K Collecting one's own plants for use as herbal medicines is pe ...
- HDU - 5887:Herbs Gathering (map优化超大背包)
Collecting one's own plants for use as herbal medicines is perhaps one of the most self-empowering t ...
- HDU 5887 Herbs Gathering
背包,$map$,优化. 和普通背包一样,$map$加一个$erase$优化一下就可以跑的很快了. #pragma comment(linker, "/STACK:1024000000,10 ...
- HDU 5887 Herbs Gathering(搜索求01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=5887 题意: 容量很大的01背包. 思路: 因为这道题目背包容量比较大,所以用dp是行不通的.所以得用搜索来做, ...
- hdu 5887 Herbs Gathering (dfs+剪枝 or 超大01背包)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5887 题解:这题一看像是背包但是显然背包容量太大了所以可以考虑用dfs+剪枝,贪心得到的不 ...
- HDU5887(SummerTrainingDay01-D)
Herbs Gathering Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 【2016 ACM/ICPC Asia Regional Qingdao Online】
[ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...
- 2016 ACM/ICPC Asia Regional Qingdao Online
吐槽: 群O的不是很舒服 不知道自己应该干嘛 怎样才能在团队中充分发挥自己价值 一点都不想写题 理想中的情况是想题丢给别人写 但明显滞后 一道题拖沓很久 中途出岔子又返回来搞 最放心的是微软微软妹可以 ...
随机推荐
- JDBC为什么要使用PreparedStatement而不是Statement
PreparedStatement是什么? PreparedStatement是java.sql包下面的一个接口,用来执行SQL语句查询,通过调用connection.preparedStatemen ...
- Getting the pixel coordinates of text or ticks in matplotlib
The exact pixel coordinates of title, labels, legends or ticks are important information for the tra ...
- Eclipse多平台编译(armeabi, armeabi-v7a, x86, mips)
Jni目录下新增Application.mk,加入 APP_ABI := armeabi armeabi-v7a x86 mips 上面的平台可加可减,全编的话可以写为 APP_ABI := all ...
- 为Docker配置阿里加速器,系统为Debian8
先停止docker服务 service docker stop 设置阿里加速器 dockerd --registry-mirror=https://063eurcd.mirror.aliyuncs.c ...
- [SCOI2007]最大土地面积
首先,最大四边形的四个点一定在凸包上 所以先求凸包 有个结论,若是随机数据,凸包包括的点大约是\(\log_2n\)个 然鹅,此题绝对不会这么轻松,若\(O(n^4)\)枚举,只有50分 所以还是要想 ...
- 【NOIP2015】运输计划
[NOIP2015]运输计划 标签: 树上差分 LCA 二分答案 Description 公元 2044 年,人类进入了宇宙纪元. L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星 ...
- sql server两个时间段内,求出周末的量
公司有个表记录了出差(加班)的初始时间和截止时间,现在要计算出加班时间,之前的设计并没有考虑到这部分,因此本人通过sql重新计算周末数 表formmain starttime endtime 使用游标 ...
- WordUtil java导出word工具类
import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedWriter ...
- .NET Core阿里大于短信发送SDK修改以及使用
一.问题背景 继上次七牛云SDK的问题之后(参考:http://www.cnblogs.com/OMango/p/8447480.html),在发送短信的功能上又出现了问题,我们短信服务使用的是阿里大 ...
- elasticsearch red status fix 红色状态修复
问题描述: spring cloud项目有用到elasticsearch,启动时进行健康校验,发现es一直是down的,导致在eureka显示也是down 问题定位:查看actuator源码发现,如果 ...