【BZOJ1046】[HAOI2007]上升序列

题面

bzoj

洛谷

题解

\(dp\)完之后随便搞一下即可,注意不要看错题

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return w * data;
}
const int MAX_N = 1e4 + 5;
int N, a[MAX_N], dp[MAX_N];
int main () {
N = gi(); for (int i = 1; i <= N; i++) a[i] = gi();
reverse(&a[1], &a[N + 1]);
fill(&dp[1], &dp[N + 1], 1);
for (int i = 1; i <= N; i++)
for (int j = 1; j < i; j++)
if (a[j] > a[i]) dp[i] = max(dp[i], dp[j] + 1);
int mx = 1;
for (int i = 1; i <= N; i++) mx = max(mx, dp[i]);
int M = gi();
while (M--) {
int l = gi();
if (l > mx) { puts("Impossible"); continue; }
else {
int now = 0;
for (int i = N; i >= 1; i--)
if (dp[i] >= l && a[i] > now) {
printf("%d ", a[i]);
now = a[i], --l;
if (!l) break;
}
printf("\n");
}
}
return 0;
}

【BZOJ1046】[HAOI2007]上升序列的更多相关文章

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

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

  2. BZOJ1046 [HAOI2007]上升序列

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

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

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

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

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

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

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

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

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

  7. bzoj1046 [HAOI2007]上升序列——LIS

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1046 倒序求最长下降子序列,则得到了每个点开始的最长上升子序列: 然后贪心输出即可. 代码如 ...

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

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

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

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

随机推荐

  1. SQL Server ->> 数据类型不一致比较时的隐式转换

    当使用操作符进行比较的时候,两边数据类型不一致的情况下,数据类型优先级别低的会往优先级别高的发生隐式转换.下面的参考链接是优先级别列表. 参考: Data Type Precedence (Trans ...

  2. Windows Pre-commit hook for comment length Subversion

    @echo off :: Stops commits that have empty log messages. @echo off setlocal rem Subversion sends thr ...

  3. MDT配置数据库

    连接数据库可以使用数据库账户和Windows集成身份验证两种方法:使用数据库账户:1.连接数据库时选择TCP/IP2.在数据库中添加相应规则后,配置数据库3.在CustomSettings.ini文件 ...

  4. Linux架构之简述企业网站简述

    简述企业网站 用户  --> 负载均衡服务器(Nginx)  ->根据扩展名访问不同的服务区 ->访问数据库 ->返回用户          静态服务器&&动态 ...

  5. 内置数据结构(str)

    一.字符串(str) 1.字符串在python2版本中为一个byte序列,在python3版本中为一个unicode序列,并且字符串是不可变的. sr = str() sr = 'string' sr ...

  6. Centos7 教程收集ing

    CentOS7 常用命令集合 https://blog.csdn.net/o0darknessyy0o/article/details/52072054#t1 1.centOS7下实践查询版本/CPU ...

  7. 查找数据库表中重复的 Image 类型值

    直接上代码: SELECT * FROM [dbo].[V_Courseware] ))) IN ())) FROM [dbo].[V_Courseware] ))) ); 替换以上代码中相应对象即可 ...

  8. September 23rd 2017 Week 38th Saturday

    Lonely people will always remember his life occurred in each person. 寂寞的人总是会用心记住他生命中出现过的每个人. If you ...

  9. Hadoop学习之路(二)Hadoop发展背景

    Hadoop产生的背景 1. HADOOP最早起源于Nutch.Nutch的设计目标是构建一个大型的全网搜索引擎,包括网页抓取.索引.查询等功能,但随着抓取网页数量的增加,遇到了严重的可扩展性问题—— ...

  10. Week4:Neural Networks难点记录

    为什么θ的维度是Sj+1*(Sj+1)? 课堂PPT没有两层单元个数不同的状态,故举一个例子就知道了 and sj+1=4, so sj+1×(sj+1)=4×3. 编程作业: Multi-class ...