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

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
 

Source

 
大容量01背包,搜索加剪枝
 //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)的更多相关文章

  1. HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)

    背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...

  2. hdu5887 Herbs Gathering

    神他妈随便写写就能过- 暴力枚举每个取不取 两个剪纸: 1.当剩下可用的时间小于最少需要用的时间 跳出 2.当剩下的植物按照理想情况(甚至可以取一部分)得到的极限答案比已经求出的答案大 跳出 #inc ...

随机推荐

  1. js- DOM事件之按钮绑定函数注意事项

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  2. 团队博客-第六周:Alpha阶段项目复审(只会嘤嘤嘤队)

    小组名 题目 优点 缺点 排名 小谷围驻广东某工业719电竞大队 广工生活社区 功能多样,设计完整,实用,界面美观 界面风格不够统一,当前时间系统尚未发布 1 大猪蹄子队 四六级背单词游戏 界面十分美 ...

  3. samba服务配置(一)

    samba是一个实现不同操作系统之间文件共享和打印机共享的一种SMB协议的免费软件. samba软件结构: /etc/samba/smb.conf    #samba服务的主要配置文件 /etc/sa ...

  4. Nextday 参数化单元测试(测试用例)设计

    一.首先简单描述一下下载试题及配置试题的过程 配置环境:安装Eclipse.JDK(1.7).及考试插件 (net.mooctest....*.jar)等: 登录系统:运行Eclipse: [Mooc ...

  5. iOS逆向之TheOS

    TheOS 被设计为一个在基于 Unix 平台 (Mac OS X.IOS…) 和大多数 的Linux 平台下开发 iOS 程序的集成开发环境.说是集成开发环境,其实就是给我们准备好了一些代码模板.预 ...

  6. WebService接口定义及调用

    Web service是一个平台独立的,松耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布式的互操作的应用程序. WebS ...

  7. 「ZJOI2018」胖(ST表+二分)

    「ZJOI2018」胖(ST表+二分) 不开 \(O_2\) 又没卡过去是种怎么体验... 这可能是 \(ZJOI2018\) 最简单的一题了...我都能 \(A\)... 首先我们发现这个奇怪的图每 ...

  8. 顺藤摸瓜:一个专黑建筑行业的QQ黏虫团伙现形记

    QQ粘虫是已经流行多年的盗号木马,它会伪装QQ登陆界面,诱骗受害者在钓鱼窗口提交账号密码.近期,360QVM引擎团队发现一支专门攻击建筑行业人群的QQ粘虫变种,它伪装为招标文档,专门在一些建筑/房产行 ...

  9. Tools - 浏览器Chrome

    Chrome HomePage:https://www.google.com/chrome/ Chrome应用商店:https://chrome.google.com/webstore/categor ...

  10. 关于Ubuntu拒绝root用户ssh远程登录

    #sudo vim /etc/ssh/sshd_config 找到并用#注释掉这行:PermitRootLogin prohibit-password 新建一行 添加:PermitRootLogin ...