标签:
题目链接:http://acm.swust.edu.cn/problem/585/
1
2
3
4
5
|
3
3 2
1 1
2 2
|
1
2
|
3
|
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 struct node{ 6 int x, y; 7 bool operator<(const node &tmp)const{ 8 if (x != tmp.x) 9 return x < tmp.x; 10 return y < tmp.y; 11 } 12 }tower[100005]; 13 14 int n, len, dp[100005]; 15 16 int binary_search(int key, int low, int high){ 17 while (low < high){ 18 int mid = (low + high) >> 1; 19 if (key >= dp[mid]) 20 low = mid + 1; 21 else high = mid; 22 } 23 return low; 24 } 25 26 int main(){ 27 int i, j; 28 while (cin >> n){ 29 for (i = 0; i < n; i++) cin >> tower[i].x >> tower[i].y; 30 sort(tower, tower + n); 31 dp[1] = tower[0].y, len = 1; 32 for (i = 1; i < n; i++){ 33 if (dp[len] <= tower[i].y) j = ++len; 34 else 35 j = binary_search(tower[i].y, 1, len + 1); 36 dp[j] = tower[i].y; 37 } 38 cout << len << endl; 39 } 40 return 0; 41 }
swust oj 585--倒金字塔(LIS最长不下降子序列)
标签:
原文地址:http://www.cnblogs.com/zYx-ac/p/4564673.html