题目链接:http://poj.org/problem?id=2533
经典问题 最长上升子序列
《挑战程序设计竞赛》原题
#include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <stack> #include <set> #include <queue> #include <vector> using namespace std; const int maxn = 1010; const int INF = 0x7fffffff; int dp[maxn]; int a[maxn]; int main() { //freopen("in.txt", "r", stdin); int n; while(scanf("%d", &n) == 1) { for(int i = 0; i < n; i++) scanf("%d", &a[i]); fill(dp, dp + n, INF); for(int i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i]; printf("%d\n", lower_bound(dp, dp + n, INF) - dp); } return 0; }