USACO06FEB Treats for the Cows

题目地址

题解

傻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 <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
#define INF 2000000000
using namespace std;
typedef long long ll;
int n,v[2005],f[2005][2005]={0};
int read(){
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(){
n=read();
for(int i=0;i<n;i++)
v[i]=read();
}
void solve(){
for(int i=0;i<n;i++)
f[i][i]=v[i]*n;
for(int j=1;j<n;j++)
for(int i=0;i+j<n;i++){
f[i][i+j]=max(f[i+1][i+j]+v[i]*(n-j),f[i][i+j-1]+v[i+j]*(n-j));
}
printf("%d\n",f[0][n-1]);
}
int main(){
init();
solve();
return 0;
}