背包,$map$,优化。

和普通背包一样,$map$加一个$erase$优化一下就可以跑的很快了。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} int n; LL m;
struct X { LL x,y; }s[]; int main()
{
while(~scanf("%d%lld",&n,&m))
{
map<LL,LL>dp;
for(int i=;i<=n;i++) scanf("%lld%lld",&s[i].x,&s[i].y); dp[]=; map<LL,LL>::iterator it;
for(int i=;i<=n;i++)
{
it=dp.end(); --it;
for (; ; )
{
LL c=it->first, v=it->second;
if(c+s[i].x<=m) dp[c+s[i].x]=max(dp[c+s[i].x],dp[c]+s[i].y);
if(it==dp.begin()) break; --it;
} it=dp.begin(); LL mx=;
for (; it != dp.end(); )
{
if (it->second!=&&it->second<=mx) dp.erase(it++);
else { mx=it->second; ++it; }
}
} LL ans=; it=dp.begin();
for (; it != dp.end(); )
{
ans=max(ans,it->second);
++it;
}
printf("%lld\n",ans);
}
return ;
}

HDU 5887 Herbs Gathering的更多相关文章

  1. HDU 5887 Herbs Gathering(搜索求01背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=5887 题意: 容量很大的01背包. 思路: 因为这道题目背包容量比较大,所以用dp是行不通的.所以得用搜索来做, ...

  2. hdu 5887 Herbs Gathering (dfs+剪枝 or 超大01背包)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5887 题解:这题一看像是背包但是显然背包容量太大了所以可以考虑用dfs+剪枝,贪心得到的不 ...

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

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

  4. hdu 5887 搜索+剪枝

    Herbs Gathering Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. HDU - 5887:Herbs Gathering (map优化超大背包)

    Collecting one's own plants for use as herbal medicines is perhaps one of the most self-empowering t ...

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

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

  7. hdu5887 Herbs Gathering

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

  8. 【2016 ACM/ICPC Asia Regional Qingdao Online】

    [ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...

  9. 2016 ACM/ICPC Asia Regional Qingdao Online

    吐槽: 群O的不是很舒服 不知道自己应该干嘛 怎样才能在团队中充分发挥自己价值 一点都不想写题 理想中的情况是想题丢给别人写 但明显滞后 一道题拖沓很久 中途出岔子又返回来搞 最放心的是微软微软妹可以 ...

随机推荐

  1. 自定义ModelValidatorProvider

    MVC数据验证原理及自定义ModelValidatorProvider实现无编译修改验证规则和错误信息 Asp.net MVC中的提供非常简单易用的数据验证解决方案. 通过System.Compone ...

  2. [转]编译 JavaScriptCore For iOS

    from: http://phoboslab.org/log/2011/06/javascriptcore-project-files-for-ios github: https://github.c ...

  3. SPI and API

    目录 背景从面向接口编程说起“接口”位于“调用方”所在的“包”中“接口”位于“实现方”所在的“包”中“接口”位于独立的“包”中需要注意的事项另外一张图备注 背景返回目录 第一次听说 SPI 是阅读&l ...

  4. 【C#】调用DOS命令

    public interface IRunConsole { void Run(); } public abstract class RunConsole:IRunConsole { public a ...

  5. HTML5-WebSocket-初探

    1.环境准备 主要是用<HTML5 程序设计>(第二版)作为学习参考资料.但是上面用的WebSocket服务器是用python写的.偶不懂python,于是得找另外一个替代实现,这里适用n ...

  6. WordPress 4.3 Beta 1 全新发布,改进了后台功能和用户体验

    WordPress 4.3 Beta 1 发布,此版本是开发版本,不建议在生产环境使用.如果要测试 WordPress 4.3 Beta 版本,可以使用 WordPress Beta Tester 插 ...

  7. SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析)

    SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析) 2013-8-20 1.    SQL查询表的行列转换/小计/统计(with  rollup,with ...

  8. PostgreSQL数据的导出导入 save your data!

    PostgreSQL数据的导出导入 导出PostgreSQL数据库中的数据: $ pg_dump -U postgres  -f mydatabase.sql  mydatabase 导入数据时首先创 ...

  9. JSTL(JSP Standard Tag Library ,JSP标准标签库)

    JSTL标签之核心标签   JSTL(JSP Standard Tag Library ,JSP标准标签库)是一个实现 Web应用程序中常见的通用功能的定制标记库集,这些功能包括迭代和条件判断.数据管 ...

  10. 安装centos6总结

    安装centos6总结 界面说明: Install or upgrade an existing system 安装或升级现有的系统 install system with basic video d ...