题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when he finds himself blocked by a river. A single raft is available for transportation. FJ knows that he must ride on the raft for all crossings and that that…
P2904 [USACO08MAR]跨河River Crossing 显然的dp 设$f[i]$表示运走$i$头奶牛,木筏停在未过河奶牛一侧所用的最小代价 $s[i]$表示一次运$i$头奶牛到对面的代价 我们枚举上次运走了$j$头,显然$f[i]=min(f[i],f[i-j]+s[j]+s[0])$(注意自己要划回来) 最后不用划回来,减去一个$s[0]$即可 end. #include<iostream> #include<cstdio> #include<cstring…
题目:洛谷2904 分析: 裸dp-- dp方程也不难想: \(dp[i]\)表示运\(i\)头牛需要的最短时间,\(sum[i]\)表示一次运\(i\)头牛(往返)所需的时间,则 \[dp[i]=min(dp[i],dp[j]+sum[i-j])(0<=j<i)\] 注意\(sum[0]\)是\(m*2\)而不是\(0\)(船上只有FJ也需要往返时间) 以及最后一次不需要返回,所以输出要减去\(m\) 代码: #include<cstdio> #include<algori…
https://www.luogu.org/problem/show?pid=2904 题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when he finds himself blocked by a river. A single raft is available for transportation. FJ knows that he must ride…
题目 动规方程 f[i]=min(f[i],f[i−j]+sum) 我们默认为新加一头牛,自占一条船.想象一下,它不断招呼前面的牛,邀请它们坐自己这条船,当且仅当所需总时间更短时,前一头奶牛会接受邀请,最多邀请前面的所有奶牛一起坐这条船. #include<iostream> #include<cstring> #include<cstdio> using namespace std; ; int n,m,mt[maxn],f[maxn]; int main(){ sc…
题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when he finds himself blocked by a river. A single raft is available for transportation. FJ knows that he must ride on the raft for all crossings and that that…
题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when he finds himself blocked by a river. A single raft is available for transportation. FJ knows that he must ride on the raft for all crossings and that that…
传送门 f[i] 表示送前 i 头牛过去再回来的最短时间 f[i] = min(f[i], f[j] + sum[i - j] + m) (0 <= j < i) ——代码 #include <cstdio> #include <iostream> , INF = ; int n, m; int sum[MAXN], f[MAXN]; inline long long read() { , f = ; char ch = getchar(); ; ) + (x <…
洛谷题目传送门 神仙思维题还是要写点东西才好. 建立数学模型 这种很抽象的东西没有式子描述一下显然是下不了手的. 因为任何位置都以\(k\)为周期,所以我们只用关心一个周期,也就是以下数都在膜\(k\)意义下. 设\(a_i\)表示\(i\)号区间长度: 对于上行列车(\(0\rightarrow n\))设\(p_0\)表示出发时刻,\(p_i(i\ge1)\)表示在\(i\)站停靠时间: 对于下行列车(\(0\leftarrow n\))设\(-q_0\)表示到站时刻,\(q_i(i\ge1…
洛谷题目传送门 闲话 看完洛谷larryzhong巨佬的题解,蒟蒻一脸懵逼 如果哪年NOI(放心我这样的蒟蒻是去不了的)又来个决策单调性优化DP,那蒟蒻是不是会看都看不出来直接爆\(0\)?! 还是要想点办法,不失一般性也能快捷地判定决策单调. 对于判定决策单调的分析 再补一句决策单调性的概念:状态转移方程形如\(f_i=\min/\max_{j=1}^{i-1} g_j+w_{i,j}\),且记\(f_i\)的最优决策点为\(p_i\)(也就是\(f_i\)从\(g_{p_i}+w_{i,p_…