题意:

求一个连续的最长子序列长度;

思路:

没看仔细还wa1了…以为LIS…

然后写了尺取吧。。。= =太不仔细了。不过收获是LIS特么写挫了然后看了学长的blog<-点我…

题目的挫code…

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL; const int N=1e5+10; int n;
int a[N]; int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]); int s,t,ans,temp;
s=t=1;
ans=1;
temp=0;
while(s<=n)
{
while(t+1<=n&&a[t]<a[t+1])
{
temp=t-s+2;
t++;
}
s=t+1;
t=t+1;
ans=max(temp,ans);
}
printf("%d\n",ans);
return 0;
}

LIS的nlogn写法:

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL; const int N=1e5+10; int n;
int dp[N];
int a[N]; int kill(int x,int len)
{
int s=1,t=len;
while(s<=t)
{
int mid=(s+t)/2;
if(dp[mid]>=x)//这里等于也写成末尾-1,主要是最后返回起点,因为最重要的是要找到哪个点比他大然后就放那
t=mid-1;
else
s=mid+1;
}
return s;
} int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]); int len=1,j; dp[1]=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]<=dp[1]) //如果a[i]比dp数组的第一位小;
j=1;
else if(a[i]>dp[len]) //如果a[i]比dp数组最大的还大;
j=++len;
else
j=kill(a[i],len); //寻找在dp数组的位置;
dp[j]=a[i];
}
printf("%d\n",len);
return 0;
}

最新文章

  1. Oracle SQL Developer 连接 MySQL
  2. python_射门小游戏
  3. spring mvc redis消息队列
  4. hibernate的一种报错
  5. vb小程序浅析
  6. 2014 Super Training #9 E Destroy --树的直径+树形DP
  7. linux更新系统之后,删除多余的开机启动项
  8. c++ builder TreeView控件节点遍历
  9. mvc上传,下载,浏览文件功能(用uploadify插件)
  10. CSS-DOM介绍
  11. 蜘蛛牌 (DFS)
  12. 20160209.CCPP体系详解(0019天)
  13. 蓝鲸 CTF web——密码泄露
  14. centos 修改hostname
  15. lombok使用
  16. Html 改变原有标签属性
  17. docsis cm 上线过程(bigwhite)
  18. 《Linux就该这么学》第十六天课程
  19. leetcode 刷题 数组类 Two Sum
  20. DB通用类:SQL Server 通用类库

热门文章

  1. PS 如何把大嘴变小嘴
  2. weex 项目开发(四)项目框架搭建 及 自定义 TabBar 组件
  3. 【c语言】二维数组中的查找,杨氏矩阵在一个二维数组中,每行都依照从左到右的递增的顺序排序,输入这种一个数组和一个数,推断数组中是否包括这个数
  4. mac系统下为emacs设置中文字体,解决乱码问题
  5. oracle 11G direct path read 非常美也非常伤人
  6. DoubleViewPager
  7. Express:模板引擎深入研究
  8. SSM整理笔记1——SSM网站初步功能设计
  9. 线程安全 对StringBuilder抛出ArrayIndexOutOfBoundsException的探究
  10. C语言文件读写Demo