Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 28473 | Accepted: 12361 |
Description
Input
Output
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
Source
#include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <map> #include <string> #include <stack> #include <cctype> #include <vector> #include <queue> #include <set> #include <iomanip> using namespace std; //#define Online_Judge #define outstars cout << "***********************" << endl; #define clr(a,b) memset(a,b,sizeof(a)) #define lson l , mid , rt << 1 #define rson mid + 1 , r , rt << 1|1 #define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++) #define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++) #define REP(i , x , n) for(int i = (x) ; i > (n) ; i--) #define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--) #define mk make_pair const int inf = 1 << 30; const int MAXN = 1000 + 150; const int maxw = 100 + 20; const int MAXNNODE = 1000 +10; const long long LLMAX = 0x7fffffffffffffffLL; const long long LLMIN = 0x8000000000000000LL; const int INF = 0x7fffffff; const int IMIN = 0x80000000; #define eps 1e-8 #define mod 20071027 typedef long long LL; const double PI = acos(-1.0); typedef double D; typedef pair<int , int> pii; const D e = 2.718281828459; int dp[MAXN]; int main() { //ios::sync_with_stdio(false); #ifdef Online_Judge freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif // Online_Judge int n , num; while(~scanf("%d", & n)) { dp[0] = -1; int top = 0; FOR(i , 0, n) { cin >>num; if(num > dp[top]) { dp[++top] = num; } else { int R = top , L = 1 ; while(L <= R) { int mid = (L + R)/ 2; if(num > dp[mid])L = mid + 1; else R = mid - 1; } dp[L] = num; } } printf("%d\n" , top); } return 0; }