现在的位置: 首页 > 综合 > 正文

Vijos1312 && Wikioi 1154 能量项链

2017年10月12日 ⁄ 综合 ⁄ 共 536字 ⁄ 字号 评论关闭

粗看一眼,,和石子归并相差无几啊。。。

那么果断AC了。。。

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define MAX 101
int n,p[MAX],opt[MAX][MAX];
int cut(int x)
{
	if ( x > n )
	x -= n;
	return x;
}
void init()
{
	cin>>n;
	for (int i = 1; i <= n; i++)
	{
		cin>>p[i];
	}
}
int main()
{
	init();
	for (int i = 1; i <= n; i++)
	{
		opt[i][1] = p[i];
	}
	for (int j = 1; j <= n; j++)
	for (int i = 1; i <= n; i++)
	{
		int end = cut(i+j);
		int ans = 0;
		for (int k = 1; k < j; k++)
		{
			int mid = cut(i+k);
			int mans = opt[i][k] + opt[mid][j-k] + p[i]*p[mid]*p[end];
			ans = max(ans,mans);
		}
		opt[i][j] = ans;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans = max(ans,opt[i][n]);
	}
	cout<<ans;
	return 0;
}

抱歉!评论已关闭.