# bzoj4038: 医疗援助

## Sample Input

6
40 200 1 300 2 10

1950

## HINT

100%的数据，n<=3000

PS：这也是jsoi2016R2D2T1
code：
 1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 using namespace std;
7 typedef long long int64;
8 char ch;
9 bool ok;
11     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
12     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
13     if (ok) x=-x;
14 }
16     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
17     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
18     if (ok) x=-x;
19 }
20 const int maxn=3005;
21 int n;
22 int64 a[maxn],sum[maxn],g[maxn][maxn],f[maxn];
23 inline int64 s(int l,int r){return sum[r]-sum[l-1];}
24 int main(){
27     for (int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
28     for (int i=1;i<=n;i++){
29         g[i][i]=0;
30         for (int j=i-1;j>=1;j--) g[i][j]=g[i][j+1]+s(j+1,i)+min(3LL*(i-j)*a[j],s(j+1,i));
31     }
32     memset(f,63,sizeof(f));
33     f[0]=0;
34     for (int i=1;i<=n;i++) for (int j=0;j<i;j++) f[i]=min(f[i],f[j]+g[i][j+1]+s(i+1,n)*(4LL*(i-j)-2));
35     printf("%lld\n",f[n]);
36     return 0;
37 }

posted @ 2016-06-14 11:58  chenyushuo  阅读(533)  评论(0编辑  收藏  举报