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 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 s…
从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=1e6+10; #define int long long int a[N],dp[N],q[N],l,r=1; int n,m,k; inlin…
题目描述 从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力 单调队列优化动态规划 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=1e6+10; #define int long long int a[N],dp[N],q[N],l,r=1;…
P3572 [POI2014]PTA-Little Bird 一只鸟从1跳到n.从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制k,求每次最少耗费多少体力 很简短的题目哼. 首先对于一个点, 他的状态一定是由前 \(k\) 个转移过来的. \(k\) 的长度在每组询问内一定, 想到用单调队列维护 \(dp\) . 不过此时单调队列里的元素有两个关键字: 劳累度和高度, 因为跳到比这个点高的树需要花费恒为一点体力(这个很重要), 所以我们维护单调队列的时候可以以劳累度为…
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 s…
P3572 [POI2014]PTA-Little Bird 首先,这道题的暴力dp非常好写 就是枚举所有能转移到他的点,如果当前枚举到的位置的值大于 当前位置的话,\(f[i]=min(f[i],f[j])\) 否则就\(f[i]=min(f[i],f[j]+1)\) 时间复杂度为O(nk) 考虑优化,因为只是加1或不加,实际上只需要知道能转移到当前节点的位置 的&f&数组最小值即可,同时也要选这个位置数值最大的(想一想为什么) 这样的话,这道题就没了 #include<iostr…
Luogu P3577 [POI2014]TUR-Tourism 题目链接 题目大意:给出一张\(n\)个点,\(m\)条边的无向图,保证任意两点之间没有点数超过\(10\)的简单路径.选择第\(i\)个点要支付\(C_i\)的代价,要求用最小的代价使得每个点被选择或者与一个被选择的点相邻. \(n\leq 20000,m\leq 25000,C_i\leq 1000\). 可以发现,如果原问题是在树上的话就很简单.所以我们先建出\(dfs\)树.因为这是无向图,所以所有的非树边都是返祖边.由题…
二次联通门 : luogu P3567 [POI2014]KUR-Couriers MMP 指针 RE + MLE + WA..... 不得已...向黑恶的数组实力低头 /* 指针 */ #include <algorithm> #include <cstdio> #define Max 2000009 void read (int &now) { now = ; register char word = getchar (); ') word = getchar ();…
题面:[POI2014]PTA-Little Bird 题解: N<=1e6 Q<=25F[i]表示到达第i棵树时需要消耗的最小体力值F[i]=min(F[i],F[j]+(D[j]>=D[i])) (j>=i-K)使用单调队列维护越小的越优,在写单调队列时,让F值最小的数越前因为F[i]-F[j]最多等于1然后如果F值相同,则D越大的越优,因为D越大,后面不用+1的概率越大大概就是这样 代码: #include<cstdio> #include<cstring&…
DP/单调队列优化 水题水题水题水题 单调队列优化的线性dp…… WA了8次QAQ,就因为我写队列是[l,r),但是实际操作取队尾元素的时候忘记了……不怎么从队尾取元素嘛……平时都是直接往进放的……还是得记住这个双端队列的错点啊!! //BZOJ 3831 #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #def…