bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】
把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max,每次转移的时候直接从树状数组上查询前缀max即可,然后把更新出来的f[i]update进树状数组
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100005;
int n,t[N],f[N],ans;
struct qwe
{
int l,r;
}a[N];
bool cmp(const qwe &a,const qwe &b)
{
return a.r<b.r;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void update(int x,int v)
{
for(int i=x;i<=n;i+=(i&(-i)))
t[i]=max(t[i],v);
}
int ques(int x)
{
int r=0;
for(int i=x;i;i-=(i&(-i)))
r=max(r,t[i]);
return r;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
a[i].l=read(),a[i].r=a[i].l+read()-1;
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
int l=1,r=i-1,w=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(a[mid].r<a[i].l)
l=mid+1,w=mid;
else
r=mid-1;
}
f[i]=ques(w)+1;
update(i,f[i]);
ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}
bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】的更多相关文章
- BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )
先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开 ...
- 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝
1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 255 S ...
- 【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1664 和之前的那题一样啊.. 只不过权值变为了1.. 同样用线段树维护区间,然后在区间范围内dp. ...
- bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝
Description Farmer John has returned to the County Fair so he can attend the special events (concert ...
- [Usaco2006 Open]County Fair Events 参加节日庆祝
Description Farmer John has returned to the County Fair so he can attend the special events (concert ...
- 【动态规划】bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝
将区间按左端点排序. f(i)=max{f(j)+1}(p[j].x+p[j].y<=p[i].x && j<i) #include<cstdio> #incl ...
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】
最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...
- 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树状数组套主席树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 首先还是吐槽时间,我在zoj交无限tle啊!!!!!!!!我一直以为是程序错了啊啊啊啊啊啊. ...
- BZOJ.4553.[HEOI2016&TJOI2016]序列(DP 树状数组套线段树/二维线段树(MLE) 动态开点)
题目链接:BZOJ 洛谷 \(O(n^2)\)DP很好写,对于当前的i从之前满足条件的j中选一个最大值,\(dp[i]=d[j]+1\) for(int j=1; j<i; ++j) if(a[ ...
随机推荐
- uva10537 最短路 倒推
题意:知道了,最后需要的,那么就倒着最短路,推出去就可以了. 以最短路的方式来解决.
- 整体二分初识--POJ2104:K-th Number
n<=100000个数有m<=5000个询问,每次问区间第k大. 方法一:主席树!…… 方法二:整体二分. 整体二分一次性计算半个值域对一个区间的询问的贡献,然后根据“这半边的贡献在某个询 ...
- Linux下汇编语言学习笔记3 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- Letter Combinations of a Phone Number(带for循环的DFS,组合问题,递归总结)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- Ubuntu 16.04下SecureCRT无法输入中文的解决思路
说明:首先网上的方法基本都是不行的,别试了. 但是可以有弥补方案: 1.通过外界的软件编辑好中文,然后粘贴过去.虽然是多了一步,但是也可以输入中文. 2.关于这个问题应该是没有中文字体库导致的,可以尝 ...
- oracle索引简单使用
--查询表索引 select * from user_ind_columns where table_name = upper('HY_PROJECT') and column_name = uppe ...
- laralvel 关系多对多
- AngularJS $q 和 $q.all 单个数据源和多个数据源合并(promise的说明)
这篇文章讲的不错, angular $q 和 promise!! -------------------------------------------------------------- 通过调 ...
- Websphere优化 (四个方面)举例
Websphere优化 一.简单介绍 环境 名称 版本号 server操作系统 Centos 5.6 应用server操作系统 Windows 7 Websphere版本号 WAS 7.0 数据库 O ...
- [TypeScript] Collect Related Strings in a String Enum in TypeScript
As of TypeScript 2.4, it is now possible to define string enums, or more precisely, enums with strin ...