[POJ1631]Bridging signals

题目大意:不知,根据样例猜测为最长上升子序列(竟然还对了)

题解:$O(n log_2 n)$,求二维偏序,(q为存答案的序列,a存原序列,len为答案)

for(int i = 1; i <= n; i++) {
    if(a[i] > q[len]) {q[++len]=a[i];continue;}
    *upper_bound(q, q + len, a[i]) = a[i];
}

卡点:

C++ Code:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int T, n ,a;
int f[40010], cnt;
int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		memset(f, 0x3f, sizeof f);
		for (int i = 0 ; i < n; i++) {
			scanf("%d", &a);
			*lower_bound(f, f + n, a) = a;
		}
		printf("%d\n",lower_bound(f, f + n, 0x3f3f3f3f) - f);
	}
	return 0;
} 

  

猜你喜欢

转载自www.cnblogs.com/Memory-of-winter/p/9288223.html
今日推荐