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. 安装Intellij IDEA(ideaIU-2017.2.3)并完成Intellij IDEA的简单配置

    一.Intellij IDEA的简介 Intellij IDEA是java语言的集成开发环境,与Eclipse相比,它的功能更多.更强大.更智能,Eclipse更适合刚学习java语言的初学者,它操作 ...

  2. iOS逆向之iOSOpenDev

    上篇谈到使用TheOS进行越狱开发,但是流程相对而言较复杂,本篇我们谈一下iOSOpenDev进行越狱开发.通过使用iOSOpenDev,我们可以使用Xcode进行开发.编译.生成并运行到设备上. 1 ...

  3. create-react-app创建的项目npm run build之后静态文件找不到

    create-react-app创建的项目npm run build之后,运行build中的index.html,什么都没显示,打开浏览器的F12,发现了几个红色的报错,提示几个文件找不到. 查看生成 ...

  4. 枚举类型enum详解——C语言

    enum enum是C语言中的一个关键字,enum叫枚举数据类型,枚举数据类型描述的是一组整型值的集合(这句话其实不太妥当),枚举型是预处理指令#define的替代,枚举和宏其实非常类似,宏在预处理阶 ...

  5. OkHttp 入门篇

    OkHttp是一个HTTP & HTTP2的客户端,能够用来进行Android 和 Java 开发. HTTP是现代应用的最基本的网络环境.让你的HTTP更加有效的工作能够让你的东西加载更快而 ...

  6. 9:集合collection

    第一 集合框架的概述 集合类的由来:  对象用于封装特有数据,对象多了需要存储,如果对象的个数不确定,就使用集合容器进行存储.   集合和数组的区别: 数组虽然可以存储对象,但是长度是固定的:集合长度 ...

  7. 使用 PLSQL 提示动态执行表不可访问,本会话的自动统计被禁止

    使用PLSQL,第一次执行表的select操作的时候,提示"动态执行表不可访问,本会话的自动统计被禁止",如上图: 这种问题,一看就是当前连接用户没有对sys用户下的表v$sess ...

  8. ElasticSearch5.0之后的改变

    ES5的变化 search_type=count和scan都移除了 count可以用size=0代替 GET /my_index/_search { "size": 0, &quo ...

  9. Testing - 软件测试知识梳理 - 测试阶段

    估算 测试对软件工作量的估算的准确性 测试评估软件系统的状况的准确性 关注点: 不准确的估算 不适当的开发过程 不真实的状态报告 如何知道对工作量的估算是正确的 估算工作量的工具很容易出错 对软件工作 ...

  10. Datatable数据转换成excel导出时 数值类型在EXCEL中为文本形式 无法进行统计

    功能背景 有地税上以及各企业的一个缴费情况的比对,基于两表进行匹配查看数据是否在合理范围内,对比对完成表进行数值导出. 2.问题描述 匹配和生成匹配结果导出已成功完成,但是在数值列导出后变成了文本形式 ...