关键在于二分查找
/*
Author:html_11
*/
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <climits>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define e 2.718281828459
#define eps 1e-10
using namespace std;
typedef long long ll;
static const int MAX_N = 1e3 + 5;
static const ll Mod = 2009;
int a[MAX_N];
int main() {
/* freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
int n;
while (scanf("%d", &n) != EOF) {
int cnt = 0;
a[cnt] = -INF;
for (int i = 0; i < n; ++i) {
int v;
scanf("%d", &v);
if (a[cnt] < v) a[++cnt] = v;
else {
int l = 1, r = cnt;
while (l <= r) {
int m = (l + r) >> 1;
if (a[m] >= v) r = m - 1;
else l = m + 1;
}
a[l] = v;
}
}
printf("%d\n", cnt);
}
return 0;
}