传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1046
求以i为开头的最长上升,即倒着做最长下降
算完之后贪心,遇到一个合法的就选择
Code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,m,size;
int a[maxn];
int d[maxn];
int f[maxn];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=n;i;i--){
int j=lower_bound(d,d+size,a[i],greater<int>())-d;
d[j]=a[i];
f[i]=j+1;
size=max(size,j+1);
}scanf("%d",&m);
while(m--){
int x,last=-1;scanf("%d",&x);
if(x>size){puts("Impossible");continue;}
for(int i=1;x&&i<=n;i++)
if(f[i]>=x&&a[i]>last)printf("%d%c",a[i]," \n"[x==1]),x--,last=a[i];
}
return 0;
}