【最长上升子序列】北大 POJ 1631 Bridging signals
2012-07-11 07:35
423 查看
/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2012 panyanyany All rights reserved. URL : http://poj.org/problem?id=1631 Name : 1631 Bridging signals Classification : 最长上升子序列 Date : Wednesday, July 11, 2012 Time Stage : half an hour Result: 10420085 panyanyany 1631 Accepted 472K 125MS C++ 1557B 2012-07-11 07:29:31 Test Data : Review : //----------------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <vector> #include <algorithm> #include <iostream> #include <queue> #include <set> #include <string> using namespace std ; #define MEM(a, v) memset (a, v, sizeof (a)) // a for address, v for value #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) #define INF (0x3f3f3f3f) #define MAXN (40005) #define L(x) ((x)<<1) #define R(x) (((x)<<1)|1) #define M(x, y) (((x)+(y)) >> 1) #define DB // int a[MAXN], order[MAXN]; int LIS(int a[], int n) { int i, u, l, m, len; len = 1; MEM(order, INF); // 找上升子序列时初始化 INF,找下降子序列时初始化为0 for (i = 0; i < n; ++i) { u = len; l = 1; while (l <= u) { m = (l + u) >> 1; if (order[m] < a[i]) l = m + 1; else u = m - 1; } if (order[l] > a[i]) order[l] = a[i]; if (len < l) len = l; // printf("^ %d ^", l); } return len; } int main() { int i, n, tc; while (scanf("%d", &tc) != EOF) { while (tc--) { scanf("%d", &n); for (i = 0; i < n; ++i) scanf("%d", a+i); printf("%d\n", LIS(a, n)); } } return 0; }
相关文章推荐
- 最长上升子序列(LIS)POJ 1631 Bridging Signals
- poj-1631-Bridging signals-最长上升序列(LIS)
- POJ 1631 Bridging signals(最长上升序列)
- poj 1631 Bridging signals【最长上升子序列】
- POJ 1631 Bridging signals(最长上升子序列 nlgn做法)
- POJ 1631 : Bridging signals - 最长上升子序列 O(nlog n)
- POJ 1631(最长上升子序列 nlogn).
- poj 1631 最长上升子序列 nlogn
- poj 1631 / nlogn 算法 求 最长上升子序列长度
- POJ 1631 Bridging signals(最长上升子序列 n*logn && POJ 3903)
- POJ 1631 HDU 1950(最长上升子序列问题)
- 【最长下降子序列】北大 POJ 1065 Wooden Sticks
- POJ_2533 Longest Ordered Subsequence【DP】【最长上升子序列】
- poj 1836 Alignment( 最长上升(下降)子序列 )
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
- 最长上升子序列 nlogn时间复杂度 poj 2533
- poj1631 Bridging signals 加强版最长上升子序列
- poj 1631离散化加树状数组优化 最长上升子序列LIS nlogn做法
- poj 3903 求最长上升子序列长度
- POJ 1836 Alignment 【最长上升(下降)子序列】