【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;
}

最新文章

  1. easy_UI 投票列表
  2. Spring4.X——搭建
  3. Linux安装Node.js
  4. C++虚函数和虚函数表
  5. WIFI功率修改
  6. HTML-正则表达式
  7. NOI2012 : 迷失游乐园
  8. java 的文件读取操作
  9. (转)Android之自定义适配器
  10. 打造自己的程序员品牌(摘自Infoq)
  11. 在mac上访问自带服务器权限问题
  12. 基于visual Studio2013解决面试题之1402选择排序
  13. Windows入门基础:1.关于CreateWindow()函数使用中遇到的问题
  14. vim 编辑中执行正则表达式
  15. [转载] Solr使用入门指南
  16. android galley实现画廊效果
  17. javascript中的in运算符
  18. (最完美)红米手机5的Usb调试模式在哪里打开的教程
  19. [转]Centos 查看端口占用情况和开启端口命令
  20. UVa140 Bandwidth 【最优性剪枝】

热门文章

  1. 判断js对象类型
  2. SqlServer触发器实现表的级联插入、级联更新
  3. 安装zabbix3.4的过程(一)
  4. October 08th 2017 Week 41st Sunday
  5. ZT 用gdb调试core dump文件
  6. 【转】爬虫的一般方法、异步、并发与框架scrapy的效率比较
  7. U-Mail如何实现邮件营销自动化?
  8. HTML5新增和废弃的标签
  9. windows10 激活方法
  10. css中的相对定位与绝对定位的区别