usaco08mar river crossing

题目地址

题解

水DP
注意划船回来的时间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
#define INF 2000000000
using namespace std;
typedef long long ll;
int sum[2505],n,f[2505]={0};
int (){
int f=1,x=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return f*x;
}
void init(){
scanf("%d%d",&n,&sum[0]);
for(int i=1;i<=n;i++)
scanf("%d",&sum[i]),
sum[i]+=sum[i-1];
}
void solve(){
fill(f,f+n+1,INF);
f[0]=0;
for(int i=1;i<=n;i++)
for(int j=i-1;j>=0;j--)
f[i]=min(f[i],f[j]+sum[i-j]+sum[0]);
printf("%dn",f[n]-sum[0]);
}
int main(){
init();
solve();
return 0;
}