题目描述

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.

输入输出样例

输入样例#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.

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 ;
}

最新文章

  1. 【转】SqlServer将没有log文件的数据库文件附加到服务器中
  2. 网页中的&lt;th&gt;&lt;/th&gt;是什么意思
  3. python有超时的windows系统时间设置代码
  4. android布局学习-使用FrameLayout和LinearLayout制作QQ空间底部导航栏
  5. [游戏模版7] Win32 最简单贴图
  6. 李洪强iOS开发之OC[008] -创建一个对象并访问实例变量
  7. .net 4中的pInvokeStackImbalance MDA默认是开启的
  8. Java并发/多线程系列——初识篇
  9. 题解 P4705 【玩游戏】
  10. selenium-启动浏览器(二)
  11. muduo学习笔记(六) 多线程的TcpServer
  12. [HDFS_add_3] HDFS 机架感知
  13. 渲染Web视图
  14. windows10配置python
  15. [日常] Go语言圣经-指针对象的方法-bit数组习题
  16. mybatis将传入0识别成空字符串
  17. IntelliJ IDEA windows与mac下常用快捷键
  18. iview框架select默认选择一个option的值
  19. sublime 配置python环境
  20. 转MVC3介绍

热门文章

  1. 超级简单的jquery轮播图demo
  2. 在JS中如何把毫秒转换成规定的日期时间格式
  3. 浏览器根对象navigator之对象属性概览
  4. R中字符串操作
  5. Android ListView左滑删除、左滑自定义功能
  6. maven 结合mybaits整合框架,打包时mapper.xml文件,mapper目录打不进war包去问题
  7. centos7上安装 mysql
  8. Nginx 泛解析配置请求映射到多端口实现二级域名访问
  9. Python常见报错问题(不定时更新)
  10. EntityFramework Code First便捷工具——数据迁移