Herbs Gathering

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 687    Accepted Submission(s): 145

Problem Description
Collecting one's own plants for use as herbal medicines is perhaps one of the most self-empowering things a person can do, as it implies that they have taken the time and effort to learn about the uses and virtues of the plant and how it might benefit them, how to identify it in its native habitat or how to cultivate it in a garden, and how to prepare it as medicine. It also implies that a person has chosen to take responsibility for their own health and well being, rather than entirely surrender that faculty to another. Consider several different herbs. Each of them has a certain time which needs to be gathered, to be prepared and to be processed. Meanwhile a detailed analysis presents scores as evaluations of each herbs. Our time is running out. The only goal is to maximize the sum of scores for herbs which we can get within a limited time.
 
Input
There are at most ten test cases.
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
For each test case, output an integer as the maximum sum of scores.
 
Sample Input
3 70
71 100
69 1
1 2
 
Sample Output
3
/*
hdu 5887 搜索+剪枝 problem:
01背包问题,只是里面的数据达到了1e9 solve:
先对所有的物品按贡献(w/v)进行排序, 当搜到第u个点时,第u+1个在剩下的贡献是最大的. 如果剩下空间的全部放
u+1物品都无法大于当前的答案,则剪去. hhh-2016-09-20 20:25:42
*/
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define key_val ch[ch[root][1]][0]
using namespace std;
const int maxn = 200100;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7; template<class T> void read(T&num)
{
char CH;
bool F=false;
for(CH=getchar(); CH<'0'||CH>'9'; F= CH=='-',CH=getchar());
for(num=0; CH>='0'&&CH<='9'; num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p)
{
if(!p)
{
puts("0");
return;
}
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} struct node
{
ll v,w;
} p[maxn]; bool cmp(node a,node b)
{
return 1.0*a.w/a.v > 1.0*b.w/b.v;
} ll ans = 0,lm;
int n; bool can_more(int u,ll val,ll &ans,ll limit)
{
ll t = limit/p[u+1].v + 1;
if(val + p[u+1].w * t >= ans)
return true;
return false;
} void dfs(int u,ll val,ll limit)
{
if(val > ans)
ans = val;
if(limit <= 0)
return ;
if(u < n && can_more(u,val,ans,limit))
{
for(int i = u+1; i <= n; i++)
{
if(limit >= p[i].v)
dfs(i,val + p[i].w,limit - p[i].v);
}
}
} void init()
{ } int main()
{
init();
while(scanf("%d%I64d",&n,&lm) != EOF)
{
for(int i =1; i <= n; i++)
{
read(p[i].v);
read(p[i].w);
}
sort(p+1,p+n+1,cmp);
ans =0 ;
dfs(0,0,lm);
print(ans);
}
}

  

hdu 5887 搜索+剪枝的更多相关文章

  1. hdu 4848 搜索+剪枝 2014西安邀请赛

    http://acm.hdu.edu.cn/showproblem.php?pid=4848 比赛的时候我甚至没看这道题,事实上不难.... 可是说实话,如今对题意还是理解不太好...... 犯的错误 ...

  2. poj 1198 hdu 1401 搜索+剪枝 Solitaire

    写到一半才发现能够用双向搜索4层来写,但已经不愿意改了,干脆暴搜+剪枝水过去算了. 想到一个非常水的剪枝,h函数为  当前点到终点4个点的最短距离加起来除以2.由于最多一步走2格,然后在HDU上T了, ...

  3. hdu 6196 搜索+剪枝

    Today, Bob plays with a child. There is a row of n numbers. One can takes a number from the left sid ...

  4. hdu 5469 Antonidas(树的分治+字符串hashOR搜索+剪枝)

    题目链接:hdu 5469 Antonidas 题意: 给你一颗树,每个节点有一个字符,现在给你一个字符串S,问你是否能在树上找到两个节点u,v,使得u到v的最短路径构成的字符串恰好为S. 题解: 这 ...

  5. hdu 5113(2014北京—搜索+剪枝)

    题意:有N*M的棋盘,用K种颜色去染,要求相邻块不能同色.已知每种颜色要染的块数,问能不能染,如果能,输出任一种染法. 最开始dfs失败了- -,优先搜索一行,搜完后进入下一列,超时.本来以为搜索不行 ...

  6. NOIP2015 斗地主(搜索+剪枝)

    4325: NOIP2015 斗地主 Time Limit: 30 Sec  Memory Limit: 1024 MBSubmit: 270  Solved: 192[Submit][Status] ...

  7. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  8. luogu 1731 搜索剪枝好题

    搜索剪枝这个东西真的是骗分利器,然鹅我这方面菜的不行,所以搜索数学dp三方面是真的应该好好训练一下 一本通的确该认真的刷嗯 #include<bits/stdc++.h> using na ...

  9. 搜索+剪枝——POJ 1011 Sticks

    搜索+剪枝--POJ 1011 Sticks 博客分类: 算法 非常经典的搜索题目,第一次做还是暑假集训的时候,前天又把它翻了出来 本来是想找点手感的,不想在原先思路的基础上,竟把它做出来了而且还是0 ...

随机推荐

  1. 20162302 实验三《敏捷开发与XP实践》实验报告

    实 验 报 告 课程:程序设计与数据结构 姓名:杨京典 班级:1623 学号:20162302 实验名称:敏捷开发与XP实践 实验器材:装有IdeaU的联想拯救者80RQ 实验目的与要求:1.代码的格 ...

  2. nyoj 移位密码

    移位密码 时间限制:1000 ms  |  内存限制:65535 KB 难度:0   描述 移位密码是最简单的一类代替密码,具体算法就是将字母表的字母右移k个位置(k<26),并对字母表长度作模 ...

  3. 什么是MQTT协议?

    MQTT协议介绍 MQTT协议是什么? MQTT(Message Queuing Telemetry Transport Protocol)的全称是消息队列遥感传输协议的缩写,是一种基于轻量级代理的发 ...

  4. docker生态系统

    我的docker学习笔记6-docker生态   1.镜像即应用       代码构建.持续集成和持续交付        DaoCloud.Quay.IO 2.催生容器托管caas服务       基 ...

  5. express学习(二)—— Post()类型和中间件

    1.数据:GET.POST 2.中间件:使用.写.链式操作 GET-无需中间件 req.query POST-需要"body-parser" server.use(bodyPars ...

  6. python/socket编程之粘包

    python/socket编程之粘包 粘包 只有TCP有粘包现象,UDP永远不会粘包. 首先需要掌握一个socket收发消息的原理 发送端可以是1k,1k的发送数据而接受端的应用程序可以2k,2k的提 ...

  7. 数据结构 Python实现

    参考博客:浅谈算法和数据结构: 一 栈和队列   Python数据结构--栈.队列的实现(一)    Python数据结构--栈.队列的实现(二)    Python数据结构--链表的实现 数据结构 ...

  8. JVM 性能调优监控工具

    声明:本文转自<https://www.cnblogs.com/anxiao/p/6796644.html?utm_source=itdadao&utm_medium=referral& ...

  9. HIve:beeline终端上在输错hive语句时,无论 Backspace还是delete 都删除不掉错误的语句,没有办法退格

    通过SecureCRT工具连上linux后,通过beeline连接上hive后,在输错hive语句时,无论 Backspace还是delete 都删除不掉错误的语句,没有办法退格. 解决方案: 第一步 ...

  10. Oracle12c:支持通过创建identity columen来实现创建自增列

    oracle12c之前如果需要创建自增列必须要通过sequence+trigger来实现.但是oracle12c已经可以像mysql,sqlserver一样通过identity column来设置自增 ...