【单调队列】【动态规划】bzoj3831 [Poi2014]Little Bird
f(i)=min{f(j)+(D(j)<=D(i))} (max(1,i-k)<=j<=i)
有两个变量,很难用单调队列,但是(引用):
如果fi<fj,i一定比j优秀。因为如果heighti≥heightj就不用说了,如果heighti<heightj,i可以花1的代价跳到高的地方,顶多和j一样,不会比j差。
如果fi=fj,那当然就是谁的height高谁优秀。
双关键字搞一下就好了。
#include<cstdio>
using namespace std;
#define N 1000001
struct Point{int x,y;};
bool operator <= (const Point &a,const Point &b){return a.x!=b.x?a.x<b.x:a.y>=b.y;}
int n,m,K,q[N];
Point dp[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&dp[i].y);
scanf("%d",&m);
for(;m;--m)
{
scanf("%d",&K);
int head=1,tail=1;
dp[1].x=0; q[1]=1;
for(int i=2;i<=K;++i)
{
dp[i].x=dp[q[head]].x+(dp[q[head]].y<=dp[i].y);
while(dp[i]<=dp[q[tail]] && tail>=head) --tail;
q[++tail]=i;
}
for(int i=K+1;i<=n;++i)
{
dp[i].x=dp[q[head]].x+(dp[q[head]].y<=dp[i].y);
if(q[head]<i-K+1) ++head;
while(dp[i]<=dp[q[tail]] && tail>=head) --tail;
q[++tail]=i;
}
printf("%d\n",dp[n].x);
}
return 0;
}
【单调队列】【动态规划】bzoj3831 [Poi2014]Little Bird的更多相关文章
- 单调队列优化DP || [Poi2014]Little Bird || BZOJ 3831 || Luogu P3572
题面:[POI2014]PTA-Little Bird 题解: N<=1e6 Q<=25F[i]表示到达第i棵树时需要消耗的最小体力值F[i]=min(F[i],F[j]+(D[j]> ...
- bzoj3831 [Poi2014]Little Bird 单调队列优化dp
3831: [Poi2014]Little Bird Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 505 Solved: 322[Submit][ ...
- 单调队列应用--BZOJ 3831 Little Bird
3831: [Poi2014]Little Bird Time Limit: 20 Sec Memory Limit: 128 MB Description In the Byteotian Lin ...
- BZOJ3831 : [Poi2014]Little Bird
设f[i]表示到i最少休息次数,f[i]=min(f[j]+(h[j]<=a[i])),i-k<=j<i,单调队列优化DP #include<cstdio> #defin ...
- 【BZOJ3831】[Poi2014]Little Bird 单调队列
[BZOJ3831][Poi2014]Little Bird Description In the Byteotian Line Forest there are trees in a row. ...
- 【bzoj3831】[Poi2014]Little Bird 单调队列优化dp
原文地址:http://www.cnblogs.com/GXZlegend/p/6826475.html 题目描述 In the Byteotian Line Forest there are t ...
- [luogu]P3572 [POI2014]PTA-Little Bird(单调队列)
P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top ...
- [luoguP3572] [POI2014]PTA-Little Bird(DP + 单调队列)
传送门 DP方程 f[i] = f[j] + (a[j] <= a[i]) ( i - k < j < i ) 要使 f[i] 最小,需要等号后面的值最小,可以用单调队列来维护. 至 ...
- BZOJ_3831_[Poi2014]Little Bird_单调队列优化DP
BZOJ_3831_[Poi2014]Little Bird_单调队列优化DP Description 有一排n棵树,第i棵树的高度是Di. MHY要从第一棵树到第n棵树去找他的妹子玩. 如果MHY在 ...
随机推荐
- 洛谷P1522 牛的旅行 Cow Tours
---恢复内容开始--- P1522 牛的旅行 Cow Tours189通过502提交题目提供者该用户不存在标签 图论 USACO难度 提高+/省选-提交该题 讨论 题解 记录 最新讨论 输出格式题目 ...
- python3初识selenium
第一步:安装与配置 1.电脑上需要有火狐浏览器(默认安装在C:\Program Files (x86)\Mozilla Firefox目录下). 2.使用pip install selenium安装好 ...
- SICAU-OJ: A|B
A|B 题意: 给出一个整数n(1<=n<=10100),求Σd(d满足d可以整除n),同时保证不存在x^2有x^2可以整除n. 另外,n的质因子满足小于等于1000. 题解: 这题是我第 ...
- gogole调试请求体的数据怎么知道
在network---->header->request payload中看 详细情况见下图所示:
- maven 压缩、合并 js, css
转载自:http://blog.csdn.net/fangxing80/article/details/17639607 我们知道在 Web 应用开发中为了提高客户端响应速度,需要将页面使用的资源最小 ...
- input 单选按钮radio 取消选中(转载)
input单选按钮: 在radio按钮中添加属性tag 0代表未被选中 HTML代码: <input name="rdo1" value="AA" ty ...
- HDFS之FileSystem
package cn.hx.test; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; impo ...
- RGB颜色原理
参考:http://www.cnblogs.com/harrytian/archive/2012/12/12/2814210.html 工作中经常和颜色打交道,但却从来没有从原理上了解一下,这篇文章希 ...
- 【Foreign】阅读 [线段树][DP]
阅读 Time Limit: 10 Sec Memory Limit: 256 MB Description Input Output Sample Input 0 10 4 10 2 3 10 8 ...
- C语言ASM汇编内嵌语法
转载:http://www.cnblogs.com/latifrons/archive/2009/09/17/1568198.html C语言ASM汇编内嵌语法 .3 GCC Inline ASM G ...