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的不是很舒服 不知道自己应该干嘛 怎样才能在团队中充分发挥自己价值 一点都不想写题 理想中的情况是想题丢给别人写 但明显滞后 一道题拖沓很久 中途出岔子又返回来搞 最放心的是微软微软妹可以 ...
随机推荐
- Laravel (5.5.33) 加载过程(一)
说明: 由于公司项目使用Laravel 框架 也是第一次接触此框架 作为一个新手 记录使用过程的一些事情 以及对于框架源码分析的记录 整理自己的思路 也希望对大家有帮助 如果那里不对的地方 ...
- NOIP 2017 day 1 游记
心情非常复杂.大概就是我问到的所有人都A掉了T1那样. 的确没有按套路出牌,今年T1不是大模拟,反倒是T2. ……已经不想再提到今天的T1了.如果真的要我说,我只能说 我再次学了一整年的OI,结果栽到 ...
- Vigenère 密码
略简单的字符串+模拟. 原题链接:https://www.luogu.org/problem/show?pid=1079#sub 如果你对那个图感到懵逼,那属于正常,但没关系,这个图其实作用不大,我们 ...
- BZOJ 1758: [Wc2010]重建计划 [暂时放弃]
今天晚上思维比较乱,以后再写写吧#include <iostream> #include <cstdio> #include <cstring> #include ...
- spring security 4 filter 顺序及作用
Spring Security 有两个作用:认证和授权 一.Srping security 4 filter 别名及顺序 spring security 4 标准filter别名和顺序,因为经常要用就 ...
- Windows Azure Platform Introduction (14) 申请海外的Windows Azure账户
<Windows Azure Platform 系列文章目录> 本文的最后更新时间为:2017-12-27 本文介绍国内用户,注册和使用海外Azure账户. 前提: 1.需要一个有效的Wi ...
- Leetcode刷题C#版之Toeplitz Matrix
题目: Toeplitz Matrix A matrix is Toeplitz if every diagonal from top-left to bottom-right has the sam ...
- 将html table 转成 excel
package com.sun.office.excel; /** * 跨行元素元数据 * */ public class CrossRangeCellMeta { public CrossRange ...
- [Python Study Notes]异常处理
正则表达式 python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误.你可以使用该功能来调试python程序. 异常处理 断言(Assertions) python标准异常 ...
- JavaScript 中的对象深度复制(Object Deep Clone)
JavaScript中并没有直接提供对象复制(Object Clone)的方法. JavaScript中的赋值,其实并不是复制对象,而是类似`c/c++`中的引用(或指针),因此下面的代码中改变对象b ...