洛谷P3572 [POI2014]PTA-Little Bird
P3572 [POI2014]PTA-Little Bird
题目描述
In the Byteotian Line Forest there are nn trees in a row.
On top of the first one, there is a little bird who would like to fly over to the top of the last tree.
Being in fact very little, the bird might lack the strength to fly there without any stop.
If the bird is sitting on top of the tree no. i, then in a single flight leg it can fly toany of the trees no. i+1,i+2,\cdots,i+ki+1,i+2,⋯,i+k, and then has to rest afterward.
Moreover, flying up is far harder to flying down. A flight leg is tiresome if it ends in a tree at leastas high as the one where is started. Otherwise the flight leg is not tiresome.
The goal is to select the trees on which the little bird will land so that the overall flight is leasttiresome, i.e., it has the minimum number of tiresome legs.
We note that birds are social creatures, and our bird has a few bird-friends who would also like to getfrom the first tree to the last one. The stamina of all the birds varies,so the bird's friends may have different values of the parameter kk.
Help all the birds, little and big!
从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力
输入输出格式
输入格式:
There is a single integer nn (2\le n\le 1\ 000\ 0002≤n≤1 000 000) in the first line of the standard input:
the number of trees in the Byteotian Line Forest.
The second line of input holds nn integers d_1,d_2,\cdots,d_nd1,d2,⋯,dn (1\le d_i\le 10^91≤di≤109)separated by single spaces: d_idi is the height of the i-th tree.
The third line of the input holds a single integer qq (1\le q\le 251≤q≤25): the number of birds whoseflights need to be planned.
The following qq lines describe these birds: in the ii-th of these lines, there is an integer k_iki (1\le k_i\le n-11≤ki≤n−1) specifying the ii-th bird's stamina. In other words, the maximum number of trees that the ii-th bird can pass before it has to rest is k_i-1ki−1.
输出格式:
Your program should print exactly qq lines to the standard output.
In the ii-th line, it should specify the minimum number of tiresome flight legs of the ii-th bird.
输入输出样例
9
4 6 3 6 3 7 2 6 5
2
2
5
2
1
说明
从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000010
using namespace std;
int n,a[maxn],dp[maxn],q;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
scanf("%d",&q);
int limit;
for(int i=;i<=q;i++){
scanf("%d",&limit);
memset(dp,/,sizeof(dp));
dp[]=;
for(int i=;i<=n;i++){
for(int j=i-;i-j<=limit&&j>=;j--){
if(a[j]>a[i])dp[i]=min(dp[i],dp[j]);
else dp[i]=min(dp[i],dp[j]+);
}
}
printf("%d\n",dp[n]);
}
}
40分 暴力dp
/*
非常标准的单调队列优化dp
维护两个单调性,首先是dp[]单调递减,其次是a[]单调递增
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000010
using namespace std;
int n,op,a[maxn],dp[maxn],q[maxn],h,t;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
scanf("%d",&op);
int limit;
for(int i=;i<=op;i++){
scanf("%d",&limit);
h=,t=;
dp[]=;q[]=;
for(int i=;i<=n;i++){
while(t-h>=&&i-q[h]>limit)h++;
dp[i]=dp[q[h]]+(a[q[h]]<=a[i]);
while(t-h>=&&((dp[q[t]]>dp[i])||(dp[q[t]]==dp[i]&&a[q[t]]<a[i])))t--;
q[++t]=i;
}
printf("%d\n",dp[n]);
}
}
100分 单调队列优化dp
洛谷P3572 [POI2014]PTA-Little Bird的更多相关文章
- 洛谷 P3580 - [POI2014]ZAL-Freight(单调队列优化 dp)
洛谷题面传送门 考虑一个平凡的 DP:我们设 \(dp_i\) 表示前 \(i\) 辆车一来一回所需的最小时间. 注意到我们每次肯定会让某一段连续的火车一趟过去又一趟回来,故转移可以枚举上一段结束位置 ...
- 洛谷 P3573 [POI2014]RAJ-Rally 解题报告
P3573 [POI2014]RAJ-Rally 题意: 给定一个\(N\)个点\(M\)条边的有向无环图,每条边长度都是\(1\). 请找到一个点,使得删掉这个点后剩余的图中的最长路径最短. 输入输 ...
- 洛谷——P3576 [POI2014]MRO-Ant colony
P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...
- 洛谷 P3576 [POI2014]MRO-Ant colony
P3576 [POI2014]MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. ...
- 洛谷P3576 [POI2014]MRO-Ant colony [二分答案,树形DP]
题目传送门 MRO-Ant colony 题目描述 The ants are scavenging an abandoned ant hill in search of food. The ant h ...
- 2018.09.14 洛谷P3567 [POI2014]KUR-Couriers(主席树)
传送门 简单主席树啊. 但听说有随机算法可以秒掉%%%(本蒟蒻并不会) 直接维护值域内所有数的出现次数之和. 当这个值不大于区间总长度的一半时显然不存在合法的数. 这样在主席树上二分查值就行了. 代码 ...
- 洛谷P3567[POI2014]KUR-Couriers(主席树+二分)
题意:给一个数列,每次询问一个区间内有没有一个数出现次数超过一半 题解: 最近比赛太多,都没时间切水题了,刚好日推了道主席树裸题,就写了一下 然后 WA80 WA80 WA0 WA90 WA80 ?? ...
- 【刷题】洛谷 P3573 [POI2014]RAJ-Rally
题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...
- [洛谷P3567][POI2014]KUR-Couriers
题目大意:给一个数列,每次询问一个区间内有没有一个数出现次数超过一半.有,输出这个数,否则输出$0$ 题解:主席树,查询区间第$\bigg\lfloor\dfrac{len+1}{2}\bigg\rf ...
随机推荐
- Django的模型层(2)---多表操作
多表操作 创建模型 实例:我们来假定下面这些概念,字段和关系 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情模型和作者模型之间是一对 ...
- java.lang.UnsupportedClassVersionError: com/dw/Function : Unsupported major.minor version 52.0
本地环境中有jdk7和jdk8,当把jdk8改为jdk7时,出现如下错误,是jdk版本的问题,在Properties-->JAVA Compiler-中的Compiler compliance ...
- Android系统Gps分析(一)【转】
本文转载自:http://blog.csdn.net/xnwyd/article/details/7198728 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 1 G ...
- oracle数据库如何备份一张表
--用户名:tms--创建表ts_dictionary的备份create table ts_dictionary_20160715 as select * from ts_dictionary; 补充 ...
- 如何用命令行删除EasyBCD开机选择项?
用硬盘安装Ubuntu方法的windows双系统电脑上面,很多人都是用EasyBCD设置的开机启动选择.所以当我们不需要双系统的时候,或者已经删除双系统后,或者安装双系统失败的情况下,发现电脑的开机启 ...
- ios审核过程十大常见被拒问题
欢迎加入ios马甲包经验交流群,群聊号码:744520623 2018年伊始,苹果并没有因为新年的气氛而对CP们“网开一面”.频繁锁榜.调整排名规则以及关键词覆盖算法……不断抛出的大动作,让CP们叫苦 ...
- js正则表达式(2)
找到以某个字符串开头的字符串 var myReg=/^(abc)/gim; 如果不加m,那么只找一行,而加了m可以找到每行中以该字符串开头的匹配文本. 如: abcsfsdfasd7890hklfah ...
- codeforces 659D D. Bicycle Race(水题)
题目链接: D. Bicycle Race time limit per test 1 second memory limit per test 256 megabytes input standar ...
- android自定义控件(五) 自定义组合控件
转自http://www.cnblogs.com/hdjjun/archive/2011/10/12/2209467.html 代码为自己编写 目标:实现textview和ImageButton组合, ...
- 苹果手机app试玩平台汇总--手机链接入口
注意: 点击下载,根据提示步骤走即可. 下载后绑定手机号和微信后.才能提现 每天3点更新任务,4点最多! | 平台 | 提现额 | 任务量| 推荐强度 | 下载 | 1.小鱼,10元,大量,强推! → ...