标签:
Problem Description
///1085422276 #include<bits/stdc++.h> using namespace std; //#pragma comment(linker, "/STACK:102400000,102400000") using namespace std ; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define pb push_back inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){ if(ch==‘-‘)f=-1;ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘){ x=x*10+ch-‘0‘;ch=getchar(); }return x*f; } //**************************************** const int N=100000+50; #define mod 1000000007 #define inf 1000000007 int b[N],a[N],dp[N],l[N],r[N],n,L; int main() { int T=read();int oo=1; while(T--) { mem(a),mem(b); scanf("%d%d",&n,&L); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); }a[++n]=inf; for(int i=1;i<=n;i++) { b[n-i+1]=-a[i]; } fill(dp+1,dp+n+1,inf+2); for(int i=L+1;i<=n;i++) { int tmp=lower_bound(dp+1,dp+n+1,a[i])-dp; l[i]=tmp; tmp=lower_bound(dp+1,dp+n+1,a[i-L])-dp; dp[tmp]=a[i-L]; } fill(dp+1,dp+n+1,inf); for(int i=1;i<=n;i++) { int tmp=lower_bound(dp+1,dp+n+1,b[i])-dp; r[n-i+1]=tmp; dp[tmp]=b[i]; } //for(int i=1;i<=n;i++)cout<< l[i]<<" "; //cout<<endl; //for(int i=1;i<=n;i++)cout<< r[i]<<" "; int ans=0; for(int i=L+1;i<=n;i++) { ans=max(ans,l[i]+r[i]-2); } printf("Case #%d: ",oo++); cout<<ans<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4952511.html