【BZOJ1046】[HAOI2007]上升序列
【BZOJ1046】[HAOI2007]上升序列
题面
题解
\(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]上升序列的更多相关文章
- BZOJ1046 [HAOI2007]上升序列 【LIS + 字典序最小】
1046: [HAOI2007]上升序列 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5410 Solved: 1877 [Submit][St ...
- BZOJ1046 [HAOI2007]上升序列
Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...
- 2014.8.15模拟赛【公主的工作】&&bzoj1046[HAOI2007]上升序列
bzoj题目是这样的 Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm ...
- [BZOJ1046] [HAOI2007] 上升序列 (dp)
Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...
- 【动态规划】【最长上升子序列】【贪心】bzoj1046 [HAOI2007]上升序列
nlogn求出最长上升子序列长度. 对每次询问,贪心地回答.设输入为x.当前数a[i]可能成为答案序列中的第k个,则若 f[i]>=x-k && a[i]>ans[k-1] ...
- BZOJ1046: [HAOI2007]上升序列(LIS)
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 5740 Solved: 2025[Submit][Status][Discuss] Descript ...
- bzoj1046 [HAOI2007]上升序列——LIS
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1046 倒序求最长下降子序列,则得到了每个点开始的最长上升子序列: 然后贪心输出即可. 代码如 ...
- [BZOJ1046][HAOI2007]上升序列 DP+贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1046 我们先求出对于每一个数字作为开头的LCS的长度f[i],最长的f[i]为mxlen. ...
- 【BZOJ-1046】上升序列 DP + 贪心
1046: [HAOI2007]上升序列 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3723 Solved: 1271[Submit][Stat ...
随机推荐
- Invalid argument during startup: unknown conf file parameter : requirepass
redis 设置来密码,出现来这个错误, 把配置文件那一行的 空格 去掉 # requirepass foobared 改成 requirepass 123456 因为# 和 requirepass ...
- Linux HugePages 配置与 Oracle 性能关系说明
一. HugePages 说明 1.1 HugePages 介绍 HugePages is a feature integrated into the Linux kernel with relea ...
- ARC下的block导致的循环引用问题解析
ARC下的block导致的循环引用问题解析 更详细细节请参考 http://blog.sina.com.cn/s/blog_8c87ba3b0101m599.html ARC下,copy到堆上的blo ...
- [翻译] OCMaskedTextField
OCMaskedTextField https://github.com/OmerCora/OCMaskedTextField Simple class to display dynamically ...
- 铁乐学python_Day42_锁和队列
铁乐学python_Day42_锁和队列 例:多个线程抢占资源的情况 from threading import Thread import time def work(): global n tem ...
- Asp.net Core相关教程及开源项目推荐
入门 全新的ASP.NET: https://www.cnblogs.com/Leo_wl/p/5654828.html 在IIS上部署你的ASP.NET Core项目: https://www.c ...
- XGBoost 输出特征重要性以及筛选特征
1.输出XGBoost特征的重要性 from matplotlib import pyplot pyplot.bar(range(len(model_XGB.feature_importances_) ...
- Java8新特性 -- 四大内置的核心函数式接口
可以把这些函数式接口作为方法的参数. 1.0 核心内置函数式接口一: 消费型接口@FunctionalInterfacepublic interface Consumer<T> { voi ...
- apache ActiveMQ之初体验
版权声明: https://blog.csdn.net/zdp072/article/details/27237549 一. 开篇语 继上一篇weblogic中使用jms发送和接受消息的文章后, 本文 ...
- OOP——构造函数、析构函数
我们在创建和销毁对象时需要执行一些任务.例如,在创建对象时给属性赋值,在对象销毁时关闭数据连接等,这时就需要构造函数和析构函数. 在PHP中构造函数和析构函数是固定的,如下: // 构造函数 func ...