zoukankan      html  css  js  c++  java
  • P2215 [HAOI2007]上升序列 DP

    这个字典序海星


    思路:(DP)

    提交:4次

    错因:刚开始把字典序理解错了,怒看题解一脸懵逼;后来往前跳的时候又没有管上升(QwQ)窝太菜了。

    题解:

    所谓的字典序是相对位置!!!而不是元素本身的大小!!!

    先求出每个点往后的的最长上升子序列。
    然后对于每个询问,若询问的长度(len>=)最长的上升子序列的长度,直接(Impossible)
    否则,我们从第一个点开始找长度(>=len)的点,找到后(--len),接着向后找;直到(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

  • 相关阅读:
    python相关遗漏知识点补充
    关于viewpager的滑动问题
    C++学习一二
    Neo4j 爬坑笔记for3.2.6
    ZTree简单粗暴快速使用
    阅读HashMap——jdk7时遇到的问题记录
    【安装】Hadoop2.8.0搭建过程整理版
    html、jsp页面标签的遍历
    tomcat配置多个数据源
    java线程
  • 原文地址:https://www.cnblogs.com/Jackpei/p/11229048.html
Copyright © 2011-2022 走看看