LIS (n*logn)
2016-07-19 20:43
281 查看
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=1e6+10; int cnt=0,n,m,p,a[maxn],dp[maxn],b[maxn]; int main() { while(~scanf("%d",&n)) { for(int i=1; i<=n; i++) { scanf("%d%d",&m,&p); a[m]=p; dp[m]=1; } int l,r,mid,maxi=0,len=0; for(int i=1; i<=n; i++) { int num=a[i]; l=1; r=len; while(l<=r) { mid=(r+l)>>1; if(b[mid]<num) l=mid+1; else r=mid-1; } b[l]=num; dp[i]=l; if(l>len) len=l; if(dp[i]>maxi) maxi=dp[i]; } int maxx=0; for(int i=1; i<=n; i++) { maxx=max(maxx,dp[i]); } printf("%d\n",maxx); } return 0; }
相关文章推荐
- jQuery 之 获取并设置 CSS 类(十)
- 《剑指offer》数组中出现次数超过一半的数字
- 下面代码不能正确输出hello的选项为
- 多校&&HDU 5726 GCD
- 基本规则
- 怎样在Git码云上上传项目
- 青蛙跳台阶问题
- 冒泡排序代码
- tuxedo linux 安装
- 动态规划--最长公共子串
- hdoj1872稳定排序(sort+结构体)
- 弄提纲【NOIP2016提高A组模拟7.19】
- mysql数据对象
- SpringMVC(二)ContextLoaderListenner
- LIS
- 美团Android自动化之旅—生成渠道包
- 学渣!面对疾风吧!哈撒给
- 【杭电oj】2085 - 核反应堆(数学)
- hdu5726 GCD(gcd +二分+rmq)
- log(三)——MDCAdapter之实现LogbackMDCAdapter