标签:
Description
Input
Output
Sample Input
6 5 2 1 4 5 3 3 1 1 1 4 4 3 2 1
Sample Output
3 1 1
Hint
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; int a[100005], num[100005]; int dichotomy(int len ,int n){ int left = 1,right = len; int mid; while(left <= right){ mid = (right + left)/2; if(num[mid] == n ) return mid; else if(num[mid] > n) right = mid - 1; else if(num[mid] < n) left = mid + 1;//如果后面的数小于前面的书就把原来的给覆盖掉,如果后面数大于前面的数,就加一个,大多数情况是超出了while的条件出去的,跟mid关系不大. } return left; } int main(){ int n; while(~scanf("%d",&n)){ for(int i = 1; i <= n; i++){ scanf("%d", &a[i]); } num[1] = a[1]; int len = 1; for(int i = 1; i <= n; i++){ int j = dichotomy(len,a[i]); num[j] = a[i]; if(j > len) len = j;//记录上升的个数 } printf("%d\n", len); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4313513.html