//求最长递增子序列,和题目2533、1887、3903等是同一类型的题目!做法差不多!
#include <iostream>
#include <cstdio>
#include <memory.h>
using namespace std;
const int MAX = 400010;
int single[MAX], tmp[MAX];
int main()
{
int tc, i, n, left, right, mid, ans;
scanf("%d", &tc);
while (tc--){
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &single[i]);//原来用scanf真的比cin要快很多,尤其是在多数据输入的情况之下,一个用时454ms,一个才94ms!
ans = 0;
tmp[0] = -1;
for (i = 0; i < n; i++){
if (single[i] > tmp[ans]){
tmp[++ans] = single[i];
}
else{
left = 1, right = ans;
while (left <= right){
mid = (left + right) / 2;
if (single[i] > tmp[mid]){
left = mid + 1;
}
else{
right = mid - 1;
}
}
tmp[left] = single[i];
}
}
printf("%d\n", ans);
}
system("pause");
}
poj 1631 Bridging signals
最新推荐文章于 2022-05-10 19:32:15 发布