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…
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…
题目描述 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…
题目:洛谷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…
题目描述 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 <…
洛谷题目传送门 用两种不一样的思路立体地理解斜率优化,你值得拥有. 题意分析 既然所有的土地都要买,那么我们可以考虑到,如果一块土地的宽和高(其实是蒟蒻把长方形立在了平面上)都比另一块要小,那么肯定是直接并购,这一块对答案没有任何贡献. 我们先把这些给去掉,具体做法可以是,按高为第一关键字,宽为第二关键字从大到小排序,然后上双指针扫一遍. 于是,剩下的就是一个高度递减.宽度递增的矩形序列.考虑怎样制定它们的并购方案会最优.显然如果要并购,一定要挑序列中的一段区间,这样贡献答案的就只有最左边矩形的…
P2900 [USACO08MAR]土地征用Land Acquisition 题目描述 约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地.如果约翰单买一块土 地,价格就是土地的面积.但他可以选择并购一组土地,并购的价格为这些土地中最大的长 乘以最大的宽.比如约翰并购一块3 × 5和一块5 × 3的土地,他只需要支付5 × 5 = 25元, 比单买合算. 约翰希望买下所有的土地.他发现,将这些土地分成不同的小组来并购可以节省经费. 给定每份土地的尺寸,请你帮助他计算购买所有土地所需的最小费…