欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

P2858 [USACO06FEB]Treats for the Cows G/S (区间DP)

程序员文章站 2022-07-16 09:35:35
...

P2858 [USACO06FEB]Treats for the Cows G/S (区间DP)

题目传送门

思路:
P2858 [USACO06FEB]Treats for the Cows G/S (区间DP)
AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+5;
int v[N],dp[N][N]; 
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&v[i]);
	for(int i=1,len=1;i<=n;i++,len++)
		for(int l=1,r=l+len-1;r<=n;l++,r++)
			dp[l][r]=max(dp[l+1][r]+v[l]*(n-i+1),dp[l][r-1]+v[r]*(n-i+1));
	printf("%d\n",dp[1][n]);
	return 0;
}