P2904 [USACO08MAR]跨河River Crossing
题目描述
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 adding cows to the raft makes it traverse the river more slowly.
When FJ is on the raft alone, it can cross the river in M minutes (1 <= M <= 1000). When the i cows are added, it takes M_i minutes (1 <= M_i <= 1000) longer to cross the river than with i-1 cows (i.e., total M+M_1 minutes with one cow, M+M_1+M_2 with two, etc.). Determine the minimum time it takes for Farmer John to get all of the cows across the river (including time returning to get more cows).
Farmer John以及他的N(1 <= N <= 2,500)头奶牛打算过一条河,但他们所有的渡河工具,仅仅是一个木筏。 由于奶牛不会划船,在整个渡河过程中,FJ必须始终在木筏上。在这个基础上,木筏上的奶牛数目每增加1,FJ把木筏划到对岸就得花更多的时间。 当FJ一个人坐在木筏上,他把木筏划到对岸需要M(1 <= M <= 1000)分钟。当木筏搭载的奶牛数目从i-1增加到i时,FJ得多花M_i(1 <= M_i <= 1000)分钟才能把木筏划过河(也就是说,船上有1头奶牛时,FJ得花M+M_1分钟渡河;船上有2头奶牛时,时间就变成M+M_1+M_2分钟。后面的依此类推)。那么,FJ最少要花多少时间,才能把所有奶牛带到对岸呢?当然,这个时间得包括FJ一个人把木筏从对岸划回来接下一批的奶牛的时间。
输入输出格式
输入格式:
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 contains a single integer: M_i
输出格式:
* Line 1: The minimum time it takes for Farmer John to get all of the cows across the river.
输入输出样例
说明
There are five cows. Farmer John takes 10 minutes to cross the river alone, 13 with one cow, 17 with two cows, 23 with three, 123 with four, and 124 with all five.
Farmer John can first cross with three cows (23 minutes), then return (10 minutes), and then cross with the last two (17 minutes). 23+10+17 = 50 minutes total.
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define FFor(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 100000000
#define maxn 2505
#define inf 0x3f3f3f3f int n,m;
int f[maxn];
int w[maxn];
int x;
int sum[maxn]; int main()
{
mem(f,);
cin>>n>>m;
For(i,,n)
{
cin>>x;
sum[i]+=sum[i-]+x;
w[i]+=*m+sum[i];
} f[]=;
For(i,,n)
{
For(j,,i)
{
f[i]=min(f[i],f[i-j]+w[j]);
}
// cout<<i<<":"<<f[i]<<endl;
}
f[n]-=m;
cout<<f[n]; return ;
}
P2904 [USACO08MAR]跨河River Crossing的更多相关文章
- bzoj1617 / P2904 [USACO08MAR]跨河River Crossing
P2904 [USACO08MAR]跨河River Crossing 显然的dp 设$f[i]$表示运走$i$头奶牛,木筏停在未过河奶牛一侧所用的最小代价 $s[i]$表示一次运$i$头奶牛到对面的代 ...
- 【洛谷】P2904 [USACO08MAR]跨河River Crossing(dp)
题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when ...
- 洛谷—— P2904 [USACO08MAR]跨河River Crossing
https://www.luogu.org/problem/show?pid=2904 题目描述 Farmer John is herding his N cows (1 <= N <= ...
- 洛谷 P2904 [USACO08MAR]跨河River Crossing
题目 动规方程 f[i]=min(f[i],f[i−j]+sum) 我们默认为新加一头牛,自占一条船.想象一下,它不断招呼前面的牛,邀请它们坐自己这条船,当且仅当所需总时间更短时,前一头奶牛会接受邀请 ...
- [USACO08MAR]跨河River Crossing dp
题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when ...
- [luoguP2904] [USACO08MAR]跨河River Crossing(DP)
传送门 f[i] 表示送前 i 头牛过去再回来的最短时间 f[i] = min(f[i], f[j] + sum[i - j] + m) (0 <= j < i) ——代码 #includ ...
- 【洛谷2904/BZOJ1617】[USACO08MAR]跨河River Crossing(动态规划)
题目:洛谷2904 分析: 裸dp-- dp方程也不难想: \(dp[i]\)表示运\(i\)头牛需要的最短时间,\(sum[i]\)表示一次运\(i\)头牛(往返)所需的时间,则 \[dp[i]=m ...
- Luogu【P2904】跨河(DP)
题目链接在这里 此题DP.用一个前缀和一样的东西,把载i个奶牛的时间求出来,然后DP代码如下: ;i<=n;++i){ f[i]=que[i]; ;j<i;++j) f[i]=min(f[ ...
- USACO River Crossing
洛谷 P2904 [USACO08MAR]跨河River Crossing https://www.luogu.org/problem/P2904 JDOJ 2574: USACO 2008 Mar ...
随机推荐
- JavaScript之DOM操作(二)
这一篇写写常用并且通用的操作节点的一些方法. 1.节点方法 1>appendChild() 向childNodes列表的末尾添加一个节点,语法 var aChild = element.appe ...
- call aplly笔记
<script> /*1.每个函数都包含两个非继承而来的方法:apply()和call(). 2.他们的用途相同,都是在特定的作用域中调用函数. 3.接收参数方面不同,apply()接收两 ...
- 2018-10-15 21:07:38 c language
2018-10-15 21:07:38 c language C语言编译器,神奇的魔法师 在类 UNIX 系统(Linux.Mac OS 等)下,可执行程序没有特定的后缀,系统根据文件的头部信息来判断 ...
- Week6——Lifecycle of JSF and Facelets
一.JSF生命周期 JSF是基于事件驱动.JSF生命周期分为两个主要阶段:执行阶段和渲染阶段. 1.执行阶段 分为六个阶段: 恢复视图阶段 当客户端请求一个JavaServer Faces页面时,Ja ...
- seo关键词
除非你站有很高的权重. 小道消息称keywords曾被百度.谷歌.雅虎等搜索引擎剔除,将不会再影响搜索引擎的排序结果,小编认为设置一下总没坏处,还是有一些搜索引擎比较重视keywords标签的. 用法 ...
- [C#] Microsoft .Net框架SerialPort类的用法与示例
从Microsoft .Net 2.0版本以后,就默认提供了System.IO.Ports.SerialPort类,用户可以非常简单地编写少量代码就完成串口的信息收发程序.本文将介绍如何在PC端用C# ...
- 从本机构建Windows应用程序虚拟机映像
下图描述了总体的虚拟机映像的VHD生成,上传以及发布到 Azure 镜像市场的全过程: 具体步骤如下: 在本地计算机(Windows平台)上安装Hyper-V,并安装您所需要的虚拟机操作系统 在此操作 ...
- iOS中block类型大全
iOS中block类型大全 typedef的block 作为属性的block 作为变量的block 作为方法变量入参的block 作为方法参数的block 无名block 内联函数的block 递归调 ...
- [翻译] NSDate-TimeAgo
NSDate-TimeAgo https://github.com/kevinlawler/NSDate-TimeAgo NSDate+TimeAgo has merged with DateTool ...
- swift版的CircleView
swift版的CircleView 效果图 源码 // // CircleView.swift // CircleView // // Created by YouXianMing on 15/10/ ...