| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
TLE n次之后终于AC,贴代码#include <iostream>
#include <vector>
using namespace std;
int main()
{
const int MAX = 100000;
// 输入数据
long a[MAX];
// c[i]是以i为结束的最长串长度
int c[MAX];
// h[i]是上一个比c[i]大的c[j]位置,j=0~i-1
vector<int> h(MAX);
int n;
while (cin>>n)
{
long temp;
for (int i=0; i<n; i++)
{
cin>>temp;
a[i] = temp;
}
c[0] = 1;
h[0] = -1;
int count_max_global = 1;
for (int i=1; i<n; i++)
{
// 对a[i],从j=i-1到0搜索,找c[j]>c[i],看情况j--或跳到h[j](c[h[j]]>c[j])做下一次搜索
c[i] = 0;
int j = i-1;
while (j >= 0)
{
if (c[j] > c[i])
{
if (a[j] < a[i])
{
c[i] = c[j];
j = h[j];
}else
{
j--;
}
}else
{
j = h[j];
}
}
c[i]++;
h[i] = -1;
int k = i-1;
while (k >= 0)
{
if (c[k] > c[i])
{
h[i] = k;
break;
}else
{
k = h[k];
}
}
if (c[i] > count_max_global)
{
count_max_global = c[i];
}
}
cout<<count_max_global<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator