这个字典序海星


思路:\(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

P2215 [HAOI2007]上升序列 DP的更多相关文章

  1. bzoj 1046 : [HAOI2007]上升序列 dp

    题目链接 1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3620  Solved: 1236[Submit] ...

  2. 1046: [HAOI2007]上升序列(dp)

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4999  Solved: 1738[Submit][Stat ...

  3. [BZOJ1046] [HAOI2007] 上升序列 (dp)

    Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...

  4. P2215 [HAOI2007]上升序列

    题目描述 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1<x2<…<xm) 且(ax1<ax2<…<a ...

  5. [BZOJ1046][HAOI2007]上升序列 DP+贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1046 我们先求出对于每一个数字作为开头的LCS的长度f[i],最长的f[i]为mxlen. ...

  6. BZOJ 1046: [HAOI2007]上升序列 LIS -dp

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3438  Solved: 1171[Submit][Stat ...

  7. BZOJ 1046: [HAOI2007]上升序列【贪心+二分状态+dp+递归】

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4987  Solved: 1732[Submit][Stat ...

  8. 【BZOJ-1046】上升序列 DP + 贪心

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3723  Solved: 1271[Submit][Stat ...

  9. 【BZOJ1046】[HAOI2007]上升序列

    [BZOJ1046][HAOI2007]上升序列 题面 bzoj 洛谷 题解 \(dp\)完之后随便搞一下即可,注意不要看错题 代码 #include <iostream> #includ ...

随机推荐

  1. java 用户线程和守护线程

    在Java中通常有两种线程:用户线程和守护线程(也被称为服务线程)通过Thread.setDaemon(false)设置为用户线程通过Thread.setDaemon(true)设置为守护线程线程属性 ...

  2. uboot 与 代码重定位

    ref: https://blog.csdn.net/dhauwd/article/details/78566668 https://blog.csdn.net/yueqian_scut/articl ...

  3. 怎样在数组处理方法中使用this

    回调函数中的this不做处理的话, this仍然会指向window, 解决方法有两种. 第一种: 使用另一个变量固定this, 适用于在对象方法中使用的情况. var obj = { arr: [1, ...

  4. redis的下载和安装

    下载 http://download.redis.io 这里我们以redis的5.0.5版本和centos7环境为基础介绍 安装 1.将下载的redis-5.0.5.tar.gz文件上传到linux上 ...

  5. CCF 201803-1 跳一跳

    题目: 问题描述 近来,跳一跳这款小游戏风靡全国,受到不少玩家的喜爱. 简化后的跳一跳规则如下:玩家每次从当前方块跳到下一个方块,如果没有跳到下一个方块上则游戏结束. 如果跳到了方块上,但没有跳到方块 ...

  6. 作业16:java枚举类的秘密

    JAVA代码 public enum EnumTest { HELLO,WORLD } 字节码 public final class EnumTest extends java.lang.Enum&l ...

  7. javadoc 自动生成java帮助文档

    用法: javadoc [options] [packagenames] [sourcefiles] 选项: -public 仅显示 public 类和成员 -protected 显示 protect ...

  8. js基本对象

    1.介绍js的基本数据类型 Undefined.Null.Boolean.Number.String 2.js有哪些内置对象? 数据封装类对象:Object.Array.Boolean.Number ...

  9. Unity NavMesh 格式 解析 分析 对比 Recast Navigation

    工具软件 Excel Nodepad++ Sublime Unity 5.4 / 5.6 VS RecastDemo CodeBlocks 分析过程以Unity项目-Demo13为例 一. 创建测试模 ...

  10. python日志实时分析

    python随着人工智能的发展,越来越火热.但其实python在运维测试方面,也是一把利器. 最近就碰到了个需求,就顺手写了个python程序.用惯了go,不过发现python好像更简单点 :-) 涉 ...