日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

洛谷P3572 [POI2014]PTA-Little Bird

發布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 洛谷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\ 0002n1?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_nd?1??,d?2??,?,d?n???(1\le d_i\le 10^91d?i??10?9??)separated by single spaces:?d_id?i???is the height of the i-th tree.

The third line of the input holds a single integer?qq?(1\le q\le 251q25): 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_ik?i???(1\le k_i\le n-11k?i??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-1k?i???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.

?

輸入輸出樣例

輸入樣例#1:
9
4 6 3 6 3 7 2 6 5
2
2
5
輸出樣例#1:
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=1;i<=n;i++)scanf("%d",&a[i]);scanf("%d",&q);int limit;for(int i=1;i<=q;i++){scanf("%d",&limit);memset(dp,127/3,sizeof(dp));dp[1]=0;for(int i=2;i<=n;i++){for(int j=i-1;i-j<=limit&&j>=1;j--){if(a[j]>a[i])dp[i]=min(dp[i],dp[j]);else dp[i]=min(dp[i],dp[j]+1);}}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=1;i<=n;i++)scanf("%d",&a[i]);scanf("%d",&op);int limit;for(int i=1;i<=op;i++){scanf("%d",&limit);h=1,t=1;dp[1]=0;q[1]=1;for(int i=2;i<=n;i++){while(t-h>=0&&i-q[h]>limit)h++;dp[i]=dp[q[h]]+(a[q[h]]<=a[i]);while(t-h>=0&&((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

?

轉載于:https://www.cnblogs.com/thmyl/p/7494621.html

總結

以上是生活随笔為你收集整理的洛谷P3572 [POI2014]PTA-Little Bird的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。