POJ 1887 Testing the CATCHER[最长非升子序列O(nlog(n))]

题型:同Poj 1631.

思路:注意非升子序列需要考虑相等的情况,在二分的时候需要注意。

if (x > best[0]) {
best[
0] = x;
continue;
}
if (x <= best[sol-1]) { //key
best[sol++] = x;
continue;
}
int low = 0, high = sol-1, mid, ans;
while (low <= high) { //key
mid = (low+high)/2;
if (best[mid] < x) {
high
= mid - 1;
ans
= mid;
}
else if (best[mid] > x) {
low
= mid + 1;
}
else {
low
= mid + 1;
ans
= mid;
}
}
best[ans]
= x;

 

 

posted @ 2010-07-13 09:34  superbin  阅读(333)  评论(0编辑  收藏  举报