其他分享
首页 > 其他分享> > POJ 3186

POJ 3186

作者:互联网

水题,思路很简单,不过这里有一个另一思路,也蛮有启发性的(关于状态定义)

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 2005;

int v[maxn];
int dp[maxn][maxn];
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);

	for (int i= 1; i<= n; ++i){
		scanf("%d", v+i);
	}

	memset(dp, 0, sizeof(dp));

	for (int k= 0; k< n; ++k){
		int j= 1+k;
		for (int i= 1; j<= n; ++i, ++j){
			dp[i][j]= max(dp[i+1][j]+v[i]*(n-k), dp[i][j-1]+v[j]*(n-k));
		}
	}

	cout<<dp[1][n]<<endl;
	return 0;
}

标签:const,水题,int,3186,maxn,POJ,思路,include
来源: https://www.cnblogs.com/Idi0t-N3/p/14499080.html