UESTC 2015dp专题 N 导弹拦截 dp
导弹拦截
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/65
Description
wij 千 克的蛋糕,Gorwin从左上角(1,1)的格子开始走,走到右下角(n,m)的格子。在每一步中,Gorwin可以向右或者向下走,即是:Gorwin 站在(i,j)的时候,她可以走向(i+1,j)或者(i,j+1) (然而她不能走出这个花园)。 当Gorwin到达一个格子的时候,她可以把那个格子里面的蛋糕吃完或者不吃。但是,她不能只吃一部分。她的胃不是那么大,所以她最多只能吃K千克的蛋 糕。现在,Gorwin站在左上角,她在看蛋糕园的地图,想要找出一条路,能够使得她吃到的蛋糕最多的一条路。请你来帮帮忙。
Input
第一行是一个整数t,代表case数。 对于每一个case,第一行是一个整数n(1≤n≤100000); 第二行是n个非负整数,表示第n枚导弹的高度,按来袭导弹的袭击时间顺序给出,以空格分隔。数据保证高度不会超过100000.
Output
对于每一个case,第一行输出最多能拦截的导弹数,第二行按来袭顺序输出拦截下来的导弹的高度构成的序列,以一个空格隔开。若有不止一种方法可以拦截最多的导弹,输出字典序最小的。
Sample Input
1
5
1 6 3 5 7
Sample Output
4 1 3 5 7
HINT
题意
题解:
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <ctime>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[maxn];
int dp[maxn];
int ans[maxn];
vector<int> k;
int main()
{
int t=read();
while(t--)
{
memset(a,,sizeof(a));
memset(dp,,sizeof(dp));
memset(ans,,sizeof(ans));
k.clear();
int n=read();
for(int i=;i<=n;i++)
{
a[i]=read();
ans[i]=inf;
}
int max_ans=;
for(int i=;i<=n;i++)
{
int d=lower_bound(ans+,ans++n,a[i])-ans;
ans[d]=a[i];
dp[i]=d;
max_ans=max(max_ans,d);
}
printf("%d\n",max_ans);
int kiss=inf;
for(int i=n;i>=;i--)
{
if(!max_ans)
break;
if(dp[i]==max_ans&&a[i]<kiss)
{
kiss=a[i];
k.push_back(a[i]);
max_ans--;
}
}
int first=;
for(int i=k.size()-;i+;i--)
{
if(first)
{
printf("%d",k[i]);
first=;
}
else
printf(" %d",k[i]);
}
printf("\n");
}
}
UESTC 2015dp专题 N 导弹拦截 dp的更多相关文章
- 洛谷 P1020 导弹拦截(dp+最长上升子序列变形)
传送门:Problem 1020 https://www.cnblogs.com/violet-acmer/p/9852294.html 讲解此题前,先谈谈何为最长上升子序列,以及求法: 一.相关概念 ...
- P1020 导弹拦截 dp 树状数组维护最长升序列
题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹 ...
- 【BZOJ2044】三维导弹拦截 DP+(有上下界的)网络流
[BZOJ2044]三维导弹拦截 Description 一场战争正在A国与B国之间如火如荼的展开. B国凭借其强大的经济实力开发出了无数的远程攻击导弹,B国的领导人希望,通过这些导弹直接毁灭A国的指 ...
- UESTC 2015dp专题 H 邱老师选妹子 数位dp
邱老师选妹子 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...
- UESTC 2015dp专题 G 邱老师玩游戏 背包dp
邱老师玩游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...
- UESTC 2015dp专题 F 邱老师看电影 概率dp
邱老师看电影 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...
- UESTC 2015dp专题 E 菲波拉契数制 dp
菲波拉契数制 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...
- UESTC 2015dp专题 A 男神的礼物 区间dp
男神的礼物 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descri ...
- 【bzoj2044】三维导弹拦截 dp+二分图最大匹配
题目描述 n个物品,第i个位置有ai.bi.ci三种属性.每次可以选出满足$\ a_{p_i}<a_{p_{i+1}}\ ,\ b_{p_i}<b_{p_{i+1}}\ ,\ c_{p_i ...
随机推荐
- PHP对象2: 构造函数与析构函数
当一个对象的所有引用都没有时, 一个对象才消失, 这时才执行析构函数 <?php class firecat{ public $name; function say(){ echo 'I lov ...
- 9 - Python函数定义-位置参数-返回值
目录 1 函数介绍 1.1 为什么要使用函数 1.2 Python中的函数 2 函数的基本使用 3 函数的参数 3.1 参数的默认值 3.2 可变参数 3.2.1 可变位置传参 3.2.2 可变关键字 ...
- 选中一行并且选中该行的radio
$("tr").bind("click",function(){ $("input:radio").attr("checked&q ...
- SPOJ JZPLIT
Problem SPOJ Solution 考虑任意一个作为矩阵四个角的位置 \(r_i \oplus c_j\oplus a_{i,j}\oplus x_{i,j}=0\) \(r_i \oplus ...
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage A. Union of Doubly Link ...
- Python中的raw_input()和input()
raw_input()和input()都是python中的内建函数,用于读取控制台用户的输入,但有所区别: [nr@localhost conf]$ python Python 2.7.5 (defa ...
- python 爬图
利用bs库进行爬取,在下载html时,使用代理user_agent来下载,并且下载次数是2次,当第一次下载失败后,并且http状态码是500-600之间,然后会重新下载一次 soup = Beauti ...
- fastdfs5.10 centos6.9 安装配置
下载相关软件 https://codeload.github.com/happyfish100/fastdfs/tar.gz/V5.10http://download.csdn.net/detail/ ...
- 二叉排序树实现(C++封装)
设计思路 设计一个类,根结点只可读取,具备构造二叉树.插入结点.删除结点.查找. 查找最大值.查找最小值.查找指定结点的前驱和后继等功能接口. 二叉排序树概念 它或者是一棵空树:或者是具有下列性质的二 ...
- css写无缝滚动
html结构: <div class="authority"> <ul> <li> <img src="./images/rep ...