水DP。。。说好的n<=10000,我开到15000才过。害我WA了一版,踏马是在坑了么= =

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(i=l;i<=r;i++)
 3 #define dec(i,l,r) for(i=l;i>=r;i--)
 4 #define inf 1e9
 5 #define ll long long
 6 #define mem(a) memset(a,0,sizeof(a))
 7 #define NM 15000+5
 8 using namespace std;
 9 int read(){
10     int x=0,f=1;char ch=getchar();
11     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
12     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
13     return f*x;
14 }
15 int i,j,x,n,m,a[NM],b[NM],t,k,c[NM];
16 int main(){
17     n=read();
18     dec(i,n,1)a[i]=read();
19     a[0]=inf;
20     inc(i,1,n){
21         inc(j,0,i-1)
22         if(a[j]>a[i])b[i]=max(b[i],b[j]+1);
23     }
24     m=read();
25     inc(i,1,m){
26         k=x=read();t=0;
27         dec(j,n,1)
28         if(b[j]>=x){
29             c[x--]=a[j];
30             t=j;
31             break;
32         }
33         if(t==0)printf("Impossible\n");
34         else{
35             dec(j,t-1,1)
36             if(b[j]>=x&&a[j]>a[t]){
37                 c[x--]=a[j];
38                 t=j;
39             }
40             dec(j,k,2)printf("%d ",c[j]);
41             printf("%d\n",c[1]);
42         }
43     }
44     return 0;
45 }
View Code

 

posted on 2015-08-20 19:32  onlyRP  阅读(145)  评论(0编辑  收藏  举报