【DP】【单调队列】17.6.3 上网 题解
来源:互联网 发布:爱微游一样的软件 编辑:程序博客网 时间:2024/06/07 12:18
Normal: f[i]=max{f[i-1],f[x-1]+c[x,i]} f[0]=0
c[x,i]表示x玩到i的快乐值
Rare: 加单调队列优化
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;#define N 500100#define M 300000struct node{int x,y,c;} e[M];int n,T,tot,tree[N];inline void read(int &x){ x=0; char ch; while(ch=getchar(),ch>'9' || ch<'0'); while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();}inline int Max(int x,int y){return x>y?x:y;}inline bool cmp(node A,node B){ return A.y<B.y; }inline void insert(int x,int y){ for(;x<=T;x+=x&-x) tree[x]=Max(tree[x],y);}inline int Query(int x){ int ret=0; for(;x;x-=x&-x) ret=Max(ret,tree[x]); return ret;}int main(){ freopen("net.in","r",stdin); freopen("net.out","w",stdout); read(n); read(T); for(int i=1,m;i<=n;i++) { read(m); for(;m--;) { ++tot; read(e[tot].x); read(e[tot].y); read(e[tot].c); } } sort(e+1,e+1+tot,cmp); for(int i=1,tmp;i<=tot;i++) { tmp=Query(e[i].x-1)+e[i].c; if(tmp>Query(e[i].y)) insert(e[i].y,tmp); } printf("%d\n",Query(T)); return 0;}
阅读全文
0 0
- 【DP】【单调队列】17.6.3 上网 题解
- 【DP】【单调队列】17.6.4 假期 题解
- Hdu 3401 题解 单调队列优化DP
- 【BZOJ】【P3831】【Poi2014】【Little Bird】【题解】【单调队列+DP】
- Hdu3401 Trade(dp 单调队列优化)最详细题解
- 【DP】【斜率优化】【单调队列优化】Gift 题解
- 单调队列优化DP
- 单调队列优化DP
- 单调队列+DP
- dp单调队列优化
- hdu4374单调队列+dp
- poj3017 dp+单调队列
- 单调队列--优化dp
- 单调队列优化dp
- 单调队列优化DP
- 单调队列与DP
- 单调队列优化DP
- 单调队列优化dp
- hdoj1064 Financial Management(简单题)
- 并查集详解 (转)
- SVG概念
- POJ 1787 Charlie's Change 笔记
- windows下emacs的中文字体设置
- 【DP】【单调队列】17.6.3 上网 题解
- Android studio创建模拟器报错“Enable VT-x in your Bios Security Settings”
- 三个学生猜数字
- SDUT 3931 N!
- 线段树详解
- 向俞敏洪学习
- directors——toolofna
- 1228: 大数阶乘
- 冒泡排序