您的位置:首页 > 其它

POJ 1631 Bridging signals(LIS的等价表述)

2015-10-17 12:58 357 查看
把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述。

(如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样

O(nlogn)

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;

const int maxn = 4e4+5;
int g[maxn];

//#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; cin>>T;
while(T--){
int n, ans = 0; scanf("%d",&n);
for(int i = 0,c = 1; i < n; i++){
int x, k; scanf("%d",&x);
k = lower_bound(g+1,g+c,x)-g;
ans = max(ans,k);
g[k] = x;
if(k==c) c++; //不用把辅助数组g初始化,只要维护一个下标即可
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: