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. 23.HashMap

    HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...

  2. Js表单验证控件-02 Ajax验证

    在<Js表单验证控件(使用方便,无需编码)-01使用说明>中,写了Verify.js验证控件的基本用法,基本可以满足大多数验证需求,如果涉及服务端的验证,则可以通过Ajax. Ajax验证 ...

  3. 调用redis的时候二维码不断刷新的排查

    一.背景和现象. 项目是PHP开发的,点击登录的时候就根据随机数生成了二维码,缓存在了redis.用户用微信扫描了二维码分析出需要请求的链接,然后微信浏览器就请求了服务器,服务器通过了随机数认证.正当 ...

  4. Android NDK学习(三):Hello World

    版权声明:转载请说明出处:http://www.cnblogs.com/renhui/p/6925810.html 首先编写Jni接口的c文件,此文件命名有些特殊,具体的命名方式可以参考文档来做. # ...

  5. Java 实现 Http 请求工具类

    package com.demo.util; import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...

  6. fiddler电脑抓包和手机抓包

    概述 以前听别人说抓包抓包的,听起来很神秘高大上的样子,想入门又不知道从何学起.今天偶然在工作中遇到了以下2个需求: 改线上的代码,特别是PC端js代码. 写了一个移动端页面,由于跨域,改了host地 ...

  7. 从app上传图片到php,再上传到java后端服务器的方法一条龙服务

    在现在的网络开发中,上传图片类的需求实在是太普通不过了,但是对于怎么样做到上传图片,对于刚开始建立项目的时候,还是有点不知所措的.也许有幸,我们做的项目是之前已经有人写过类似的用例了,那么我们只需要依 ...

  8. nginx代理tomcat做负载

    先对三台服务器统一环境. 对两台tomcat服务器的操作 查看jdk环境 # java -version openjdk version "1.8.0_65" OpenJDK Ru ...

  9. vue-cli3 DllPlugin 提取公用库

    vue 开发过程中,保存一次就会编译一次,如果能够减少编译的时间,哪怕是一丁点,也能节省不少时间.开发过程中个人编写的源文件才会频繁变动,而一些库文件我们一般是不会去改动的.如果能把这些库文件提取出来 ...

  10. 阅读Google Protocol Buffers 指南,整理pb语法

    官方网站: https://developers.google.com/protocol-buffers/docs/proto3 1.简单定义一个Message 类型 pb语法文件以"*.p ...