P2215 [HAOI2007] DP rising sequence

The lexicographical starfish


Ideas: \ (DP \)

Submission: 4

Wrong because: the beginning of the lexicographical misunderstood, angry look ignorant forced to see the solution to a problem; then jump forward when they do not control rising \ (QwQ \) nest too dishes.

answer:

The so-called lexicographic order is the relative position! ! ! Not on the size of the element itself! ! !

First find each point in the future rise of the longest sequence.
Then for each ask, ask if the length \ (len> = \) the length of the longest sequence of rising directly \ (Impossible \) ;
otherwise, we started looking for a length from the first point \ (> = len \ ) the point, after finding \ (- len \) , then look backward; until \ (len == 0 \)

#include<cstdio>
#include<iostream>
#define ull unsigned long long
#define ll long long
#define R register int
using namespace std;
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
namespace Fread {
static char B[1<<15],*S=B,*D=B;
#ifndef JACK
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
#endif
inline int g() {
    R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
    if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
inline void gs(char* s) {
    register char ch; while(isempty(ch=getchar()));
    do *s++=ch; while(!isempty(ch=getchar()));
}
} using Fread::g; using Fread::gs;

namespace Luitaryi {
const int N=10010;
int n,m,mx;
int f[N],a[N];
inline void main() {
    n=g(); for(R i=1;i<=n;++i) a[i]=g();
    for(R i=1;i<=n;++i) f[i]=1;
    for(R i=n-1;i;--i) {
        for(R j=i+1;j<=n;++j) if(a[i]<a[j]) 
            f[i]=max(f[i],f[j]+1);
        mx=max(f[i],mx);
    } m=g(); while(m--) { R p=0,lst=0;
        R x=g(); if(x>mx) {puts("Impossible"); continue;}
        while(x&&++p<=n) if(a[p]>lst&&f[p]>=x) --x,printf("%d ",a[p]),lst=a[p];
        puts("");
    }
}
}
signed main() {
    Luitaryi::main(); return 0;
}

2019.07.22

Guess you like

Origin www.cnblogs.com/Jackpei/p/11229048.html