[Gym-100819S] dp+离散化
来源:互联网 发布:幼儿园美工室制度 编辑:程序博客网 时间:2024/05/19 16:05
这道题是挺好的。。可是怎么我再做还是不会。看来忘题和映像不深很严重。。
https://vjudge.net/contest/170144#problem/H
看https://vjudge.net/solution/9660165
int n;int dp[mxn];struct Node{ int l,v,r; bool friend operator<(Node a,Node b){ return a.r<b.r; }}a[mxn];map<int,int>ls;int main(){// freopen("in.txt","r",stdin); while(~sf("%d",&n)){ rep(i,1,n){ sf("%d%d%d",&a[i].l,&a[i].v,&a[i].r);a[i].r+=a[i].l-1;ls[a[i].l]=1;ls[a[i].r]=1; } map<int,int>::iterator it=ls.begin(); int cnt=0; for(;it!=ls.end();++it){it->second=++cnt; } for(int i=1;i<=n;++i){ a[i].l=ls[a[i].l]; a[i].r=ls[a[i].r]; }//这个地方的离散化可以特别针对大数据。。 sort(a+1,a+1+n); int t=1; for(int i=1;i<=cnt;++i){ dp[i]=dp[i-1]; while(t<=n&&i==a[t].r){ dp[i]=max(dp[i],dp[a[t].l-1]+a[t].v); t++;//这个地方保证了复杂度不是O(N2) } } pf("%d\n",dp[cnt]); }}
阅读全文
0 0
- [Gym-100819S] dp+离散化
- Gym 101617H dfs + 离散化 + 枚举
- Codeforces Gym 100819S Surf
- hdu3666 离散化dp
- Millionare_离散化&&DP
- 【dp+离散化】hdu 4028
- hdu5009 离散化+dp+优化
- hdu 5009 dp+离散化
- POJ3666 离散化的dp
- codeforces55D(离散化数位dp)
- 【线段树+离散化】Mayor's Posters
- 线段树+离散化Mayor's posters
- POJ_Mayor's Poster_线段树、离散化
- poj_2528Mayor's posters线段树+离散化
- POJ2528--Mayor's posters(离散化)
- poj2528Mayor's posters【线段树+离散化】
- poj2528Mayor's posters(线段树+离散化)
- poj2528Mayor's posters【离散化+线段树】
- 想成为挣钱的游戏程序员要经历多少阶段?
- sd卡写入读取
- maven国内快速镜像,国内maven中央仓库地址
- c中的移位运算法
- 向SD卡写内容并且读SD内容
- [Gym-100819S] dp+离散化
- jsp内置对象及方法
- 阿里云ecs更换系统盘(公用镜像-lnmp环境)
- 前端vue怎么实现文件上传
- hdu 6070 Dirt Ratio
- mysql详讲
- Linux-视频监控系统(8)-项目小结
- 进程基础
- 格式化字符串