背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即

if(val + (LD)pk[d].val / (LD)pk[d].w * (lim - w) + EPS <= ans){
  return;
}

没想到一发过,0ms

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
typedef long double LD; const int N = 108, INF = 0x3F3F3F3F, EPS = 0.4; struct data{
LL w, val;
bool operator<(const data &tp)const{
return val * tp.w > tp.val * w;
} }pk[N]; int n;
LL sum[N], sw[N], lim;
LL ans; void dfs(int d, LL w, LL val){
if(val > ans){
ans = val;
}
if(d >= n){
return;
}
if(val + (LD)pk[d].val / (LD)pk[d].w * (lim - w) + EPS <= ans){
return;
} if(w + pk[d].w <= lim){
dfs(d + 1, w + pk[d].w, val + pk[d].val);
}
dfs(d + 1, w, val); } int main(){
while(~scanf("%d %I64d", &n, &lim)){
for(int i = 0; i < n; i++){
scanf("%I64d %I64d", &pk[i].w, &pk[i].val);
}
sort(pk, pk + n);
ans = 0;
sum[n] = 0;
sw[n] = 0;
dfs(0, 0, 0);
printf("%I64d\n", ans); }
return 0;
}

  

HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)的更多相关文章

  1. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  2. HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)

    Herbs Gathering 10.76% 1000ms 32768K   Collecting one's own plants for use as herbal medicines is pe ...

  3. HDU 5886 Tower Defence(2016青岛网络赛 I题,树的直径 + DP)

    题目链接  2016 Qingdao Online Problem I 题意  在一棵给定的树上删掉一条边,求剩下两棵树的树的直径中较长那的那个长度的期望,答案乘上$n-1$后输出. 先把原来那棵树的 ...

  4. HDU - 5878 2016青岛网络赛 I Count Two Three(打表+二分)

    I Count Two Three 31.1% 1000ms 32768K   I will show you the most popular board game in the Shanghai ...

  5. HDU5880 Family View(2016青岛网络赛 AC自动机)

    题意:将匹配的串用'*'代替 tips: 1 注意内存的使用,据说g++中指针占8字节,c++4字节,所以用g++交会MLE 2 注意这种例子, 12abcdbcabc 故失败指针要一直往下走,否则会 ...

  6. 2016青岛网络赛 Barricade

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Proble ...

  7. 2016青岛网络赛 Sort

    Sort Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Des ...

  8. 2016青岛网络赛 The Best Path

    The Best Path Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Pr ...

  9. 2016 年青岛网络赛---Family View(AC自动机)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...

随机推荐

  1. 使用Python解析JSON数据

    使用Python解析百度API返回的JSON格式的数据 # coding:utf-8 # !/usr/bin/env python import matplotlib.pyplot as plt fr ...

  2. OncrickListener的实现

    在Java中实现的监控事件的方法 button.addActionListener(new ActionListener() { @Override public void actionPerform ...

  3. 华硕win10文档类文件点击右键时会闪一下,没法用右键打开文件

    华硕的win10系统,把系统自带的福昕软件Foxit PhantomPDF卸载了就好了

  4. Bubble Cup 8 finals G. Run for beer (575G)

    题意: 给定一个带权无向图,每条边的代价为边权/当前速度,每次到达一个新节点,速度都会除以10. 求0号点到n-1号点的最小代价,如果多解输出点数最少的解,输出代价.路径点数.路径经过的点. 1< ...

  5. JAVA连接SqlServer2008R2和MySql数据库

    问题描述: 下面是有关连接SqlServer2008R2和MySql数据库的封装类 package com.test; import java.sql.Connection; import java. ...

  6. SQL创建流水号

    创建流水号表 CREATE TABLE SystemSerialNo ( SerialNoId INT PRIMARY KEY IDENTITY, TableName VARCHAR(60), Pre ...

  7. 基础知识(05) -- Java中的类

    Java中的类 1.类的概念 2.类中的封装 3.对象的三大特征 4.对象状态 5.类与类之间的关系 ------------------------------------------------- ...

  8. Linux C 信号 pause、sigsuspend 的相同与区别

    pause函数:       功能:让进程暂停直到信号出现   #include<unistd.h>      intpause();    函数说明:pause()会令目前的进程暂停(进 ...

  9. DLL 生成与使用的全过程(2010-01-18 14:50:17)

    转载自 水滴的博客http://blog.sina.com.cn/spiritofwater   个人学习用 转载▼   分类: 技术 由dll导出的lib文件: 包含了每一个dll导出函数的符号名和 ...

  10. zabbix安装unixODBC配置完之后报错

    zabbix安装unixODBC配置完之后报错 libmysqlclient_16 not defined in file libmysqlclient_r.so.16 分析 我没有使用centos6 ...