#include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <cstdio> using namespace std; #define inf 0x3f3f3f3f int n,zeronum; int a[1000005],b[1000005],tmp[1000005],tt[1000005]; int work(){ int cnt=0; for(int i=0 ; i <=n ;i++) tt[i] = inf ; int zerocnt=0; for(int i=1 ; i <= n; i++){ if(a[i]){ b[cnt]=a[i]-zerocnt; tmp[cnt++]=a[i]-zerocnt; } else zerocnt++; } zeronum = n - cnt; sort(tmp,tmp+cnt); int size = unique(tmp,tmp+cnt)-tmp; for(int i=0; i< cnt ; i++) b[i] = lower_bound(tmp,tmp+size,b[i]) - tmp + 1; tt[0] = -1; tt[1] = b[0]; int lis=1, tk; for(int i=1; i < cnt ; i++){ tk = lower_bound(tt,tt+size+1,b[i]) - tt ; tt[tk] = b[i]; lis = max(lis, tk); } return lis; } int main(){ int t;int tp=1; cin>>t; while(tp<=t){ scanf("%d",&n);bool zero=1; int ans=0; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(zero && a[i]) zero =0; } cout<<"Case #"<<tp++<<": "; if(zero)ans=n; else{ int ll=work(); ans=zeronum+ll; } printf("%d\n",ans); } }
|