***关于lower_bound()的用法参见:http://blog.csdn.net/niushuai666/article/details/6734403***
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<cctype> #include<queue> #include<vector> #include<algorithm> using namespace std; typedef long long LL; #define N 101000 #define INF 0x3f3f3f int a[N], g[N], d[N]; int main() { int T, n, cas=1; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i=1; i<=n; i++) { g[i]=INF; scanf("%d", &a[i]); } int num, ans; num=ans=0; for(int i=1; i<=n; i++) { if(a[i]==0) { num++; continue; } a[i]-=num;//减去这个数前面零的个数,这样可以剔点一些数,为零的变换留有足够大的空间 int k=lower_bound(g+1, g+n+1, a[i])-g; d[i]=k; g[k]=a[i]; ans=max(ans, d[i]); } printf("Case #%d: %d\n", cas++, ans+num); } return 0; }
原文:http://www.cnblogs.com/9968jie/p/5718967.html