题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1046

倒序求最长下降子序列,则得到了每个点开始的最长上升子序列;

然后贪心输出即可。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int const maxn=,inf=0x7fffffff;
int n,m,l,a[maxn],b[maxn],len[maxn],cnt;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
a[b[]]=inf;
for(int i=n;i;i--)
{
if(a[b[cnt]]>a[i])
{
b[++cnt]=i;len[i]=cnt;
continue;
}
int l=,r=cnt,res;
while(l<=r)
{
int mid=(l+r)/;
if(a[b[mid]]>a[i])l=mid+;
else r=mid-,res=mid;
}
b[res]=i;len[i]=res;//i而非a[i]!
}
scanf("%d",&m);
for(int j=;j<=m;j++)
{
scanf("%d",&l);
if(cnt<l)
{
printf("Impossible\n");continue;
}
int nw=-inf;
for(int i=;i<=n;i++)
if(len[i]>=l&&a[i]>nw)
{
printf("%d ",a[i]);
nw=a[i];l--;
if(!l)break;
}
printf("\n");
}
return ;
}

bzoj1046 [HAOI2007]上升序列——LIS的更多相关文章

  1. BZOJ1046: [HAOI2007]上升序列(LIS)

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5740  Solved: 2025[Submit][Status][Discuss] Descript ...

  2. BZOJ1046 [HAOI2007]上升序列 【LIS + 字典序最小】

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 5410  Solved: 1877 [Submit][St ...

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

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

  4. BZOJ 1046: [HAOI2007]上升序列(LIS)

    题目挺坑的..但是不难.先反向做一次最长下降子序列.然后得到了d(i),以i为起点的最长上升子序列,接下来贪心,得到字典序最小. ----------------------------------- ...

  5. BZOJ1046 [HAOI2007]上升序列

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

  6. 2014.8.15模拟赛【公主的工作】&&bzoj1046[HAOI2007]上升序列

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

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

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

  8. 【动态规划】【最长上升子序列】【贪心】bzoj1046 [HAOI2007]上升序列

    nlogn求出最长上升子序列长度. 对每次询问,贪心地回答.设输入为x.当前数a[i]可能成为答案序列中的第k个,则若 f[i]>=x-k && a[i]>ans[k-1] ...

  9. BZOJ 1046 [HAOI2007]上升序列(LIS + 贪心)

    题意: m次询问,问下标最小字典序的长度为x的LIS是什么 n<=10000, m<=1000 思路: 先nlogn求出f[i]为以a[i]开头的LIS长度 然后贪心即可,复杂度nm 我们 ...

随机推荐

  1. Codeforces Round #296 (Div. 2) D. Clique Problem [ 贪心 ]

    传送门 D. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. msp430入门编程36

    msp430中C语言的可移植--面向接口实现

  3. as3corelib Tutorial:How to Use ArrayUtil Class in Flex

    ArrayUtil class contains static utility methods for manipulating and working with Arrays. Note that ...

  4. Codeforces 703C(计算几何)

    C. Chris and Road time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. java基础语法——方法,static关键字

    一:方法: 1.什么是方法: 通俗地讲,方法就是行为.它是完成特定功能的代码块能执行一个功能.它包含于类和对象中. 2.为什么要有方法: *提高代码的复用性. *提高效率 *利于程序维护 3.命名规则 ...

  6. Docker+Drone做Java/Tomcat的CI服务

    1. 安装Docker(略过) 2. 编写docker-compose.yaml version: '2' services: drone-server: image: drone/drone:0.8 ...

  7. Data obtained from ping: is it round trip or one way?

    I have 2 servers, each in two separate locations. I need to host an application on one, and the data ...

  8. leetCode 94.Binary Tree Inorder Traversal(二叉树中序遍历) 解题思路和方法

    Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tr ...

  9. Linux_C——动态库,静态库

    /usr/lib /lib:标准系统库文件          库是一组预先编译好的函数的集合,这些函数都是按照可重用的原则编写的.它们通常有一组相互关联的函数组成以          执行某项常见的任 ...

  10. Hadoop DistributedCache使用案例

    背景 公司数据处理具有两个计算框架,单机框架和MR框架.眼下我已经抽象出一套API interface, 供业务计算开发者使用. 并分别在两个计算框架下实现了API的运行调度.应用开发者有时间须要通过 ...