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. EF6 学习笔记(五):数据库迁移及部署

    EF6学习笔记总目录:ASP.NET MVC5 及 EF6 学习笔记 - (目录整理) 原文地址:Code First Migrations and Deployment 原文主要讲两部分:开发环境下 ...

  2. windows基于vs2017的opencv安装

    1.opencv下载与安装 1.下载地址:官网下载地址https://opencv.org/releases.html   opencv为开源软件,可直接在官网下载最新版本. 2.软件安装:openc ...

  3. PMP:7.项目成本管理

    内容中包含 base64string 图片造成字符过多,拒绝显示

  4. Yii2 Template 组件框架集封装

    项目简介: Yii2_Template是一个“提供大多数PHP常用的组件去集合成的一套基于Yii2的项目框架”. 该项目是一款秉着提高 开发效率.降低开发成本,遵循高拓展,高可用的原则的进行开发的框架 ...

  5. Linux - 结合正则表达式使用grep命令

    Grep with Regular Expression grep命令基本用法 grep [-acinv] [--color=auto] [-A n] [-B n] '搜寻字符串' 文件名参数说明: ...

  6. tomcat-四种运行模式和三种部署模式(优化)

    四中运行模式如下: 1-bio: 传统的Java I/O操作,同步且阻塞IO. 2-nio: JDK1.4开始支持,同步阻塞或同步非阻塞IO 3-aio(nio.2): JDK7开始支持,异步非阻塞I ...

  7. pycharm中可以运行脚本但是不能debug脚本

    以前用的时候好好地,但是最近上班突然脚本就不能debug了,debug直接报错,如下所示 上网查过该有的原因: 1.在pycharm中两个地方设置成utf-8,页面右下角和File>settin ...

  8. ubuntu下 远程连接windows服务器工具Remmina

    工具不错 https://blog.csdn.net/skykingf/article/details/71539237

  9. 课程四(Convolutional Neural Networks),第二 周(Deep convolutional models: case studies) —— 2.Programming assignments : Keras Tutorial - The Happy House (not graded)

    Keras tutorial - the Happy House Welcome to the first assignment of week 2. In this assignment, you ...

  10. 手把手教您定制化Centos6.x安装界面

    1.获取安装界面代码      挂载image/install.img:mount image/install.img /mnt/5 -o loop      复制挂载后的代码至self_intall ...