http://39.98.219.132 题库AC答案(题库序号:1853)之[USACO08MAR]River Crossing S

序号:1853

[USACO08MAR]River Crossing S

Time Limit:1s Memory Limit:125MB

题目描述

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 MM

第1行:两个以空格分隔的整数:N和M

* Lines 2..N+1: Line ii+1 contains a single integer: M_{i}

第2..N+1行:第ii+1行包含一个整数:M_{i}

输出格式

* Line 1: The minimum time it takes for Farmer John to get all of the cows across the river.

第1行:FJ让他的所有奶牛过河的最短时间

输入输出样例

输入 #1

5 10 
3 
4 
6 
100 
1 

输出 #1

50

说明/提示

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.

有5头奶牛,FJ独自渡河需要花费10分钟。和一头奶牛一起渡河需要13分钟,和两头奶牛一起渡河需要17分钟,和三头奶牛一起渡河需要23分钟,和四头奶牛一起渡河需要123分钟,和所有五头奶牛一起渡河需要124分钟。

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.

FJ可以先和三头奶牛一起渡河(23分钟),然后独自返回(10分钟),再和剩下的两头奶牛一起渡河(17分钟)。总计需要23+10+17 = 50 分钟

#include<bits/stdc++.h>
#define LL long long
#define pa pair<int,int>
#define ls k<<1
#define rs k<<1|1
#define inf 0x3f3f3f3f
using namespace std;
const int N = 3000;
const int M = 2000100;
const LL mod = 1e8;
int dp[N], sum[N];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> sum[i], sum[i] += sum[i - 1];
	for (int i = 1; i <= n; i++) dp[i] = 2e9;
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i] = min(dp[i], dp[i - j] + sum[j] + 2 * m);
		}
	}
	cout << dp[n] - m;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yys365

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值