http://www.lydsy.com/JudgeOnline/problem.php?id=1669
水题太严重
#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> using namespace std; #define rep(i, n) for(int i=0; i<(n); ++i) #define for1(i,a,n) for(int i=(a);i<=(n);++i) #define for2(i,a,n) for(int i=(a);i<(n);++i) #define for3(i,a,n) for(int i=(a);i>=(n);--i) #define for4(i,a,n) for(int i=(a);i>(n);--i) #define CC(i,a) memset(i,a,sizeof(i)) #define read(a) a=getint() #define print(a) printf("%d", a) #define dbg(x) cout << #x << " = " << x << endl #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; } inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } inline const int max(const int &a, const int &b) { return a>b?a:b; } inline const int min(const int &a, const int &b) { return a<b?a:b; } bool cmp(int x, int y) { return x<=y; } int a[5005], f[5005], g[5005]; int main() { int n=getint(), ans=0; for1(i, 1, n) read(a[i]); CC(g, 0x7f); for1(i, 1, n) { int t=lower_bound(g+1, g+1+i, a[i], cmp)-g; f[i]=t; g[t]=a[i]; ans=max(ans, t); } print(ans); return 0; }
Description
Input
Output
Sample Input
2 5 18 3 4 7 10 9 11 8 15