The topic is quite pit. But it's not hard. The longest descending subsequence is first reversed. Then I got D (i), with I as the longest ascending subsequence of the starting point, next greedy, get the dictionary order to the smallest.
-------------------------------------------------------------------
#include <cstdio>#define REP (i,n) for (int i=0;i<n;++i)using namespace std;const int maxn=10005;const int INF=0X7FFFFFFF;int A[MAXN];int G[MAXN];int D[MAXN];int lowerbound (int l,int r,int v) {int mid;While (l<r) {mid=l+ (r-l)/2;if (g[mid]<=v) R=mid;else l=mid+1;}return l;}int main (){freopen ("test.in", "R", stdin);freopen ("Test.out", "w", stdout);int n,m;scanf ("%d", &n);Rep (i,n) {scanf ("%d", &a[i]); g[i+1]=-inf;}for (int i=n-1;i>=0;--i) {int K=lowerbound (1,n,a[i]);d[i]=k;G[k]=a[i];}scanf ("%d", &m);While (m--) {int L;scanf ("%d", &l);if (g[l]==-inf) printf ("impossible");else {int last=-inf;Rep (i,n) if (d[i]>=l && a[i]>last) {printf ("%d", A[i]);if (0==--l) break;Last=a[i];printf ("");}}printf ("\ n");}return 0;}
--------------------------------------------------------------------
1046: [HAOI2007] rise sequence time limit: ten Sec Memory Limit: 162 MB
Submit: 2843 Solved: 949
[Submit] [Status] [Discuss] Description
For a given s={a1,a2,a3,..., an}, if there is p={ax1,ax2,ax3,..., AXM}, Meet (X1 < X2 < ... < XM) and (Ax1 < Ax2 < ... < AXM). Then it is called p as an ascending sequence of S. If more than one P satisfies the condition, then we want to find the one with the smallest dictionary order. The task gives a sequence of s and gives some questions. For the I inquiry, find the length of Li's ascending sequence, if there are multiple, find the smallest dictionary order (that is, first x1 the smallest, if not unique, and then see the smallest x2 ... If there is no ascending sequence with a length of Li, the impossible is printed.
Input
The first row is an n, which indicates the number of n elements in a sequence, the second row n number, for A1,a2,..., an M in the third row, indicating the frequency of the query. Next to the M line is a number L per row, which indicates that an ascending sequence of length l is to be queried.
Output
For each query, if the corresponding sequence exists, the output is otherwise printed impossible.
Sample Input6
3 4 1 2 3 6
3
6
4
5Sample OutputImpossible
1 2 3 6
ImpossibleHINT
Data range
n<=10000
m<=1000
Bzoj 1046: [HAOI2007] Ascending sequence (LIS)