#include <stdio.h>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 106;
const int inf = 0x3f3f3f3f;
int dp[maxn][maxn] = { 0 }, n;
int a[maxn];
int main()
{
while (scanf("%d", &n) != EOF)
{
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int len = 2; len < n; len++)
{
for (int i = 0; i + len < n; i++)
{
int k = i + len;
for (int j = i + 1; j < i + len; j++)
{
if (dp[i][k] == 0)
dp[i][k] = dp[i][j] + dp[j][k] + a[j] * a[i] * a[k];
dp[i][k] = min(dp[i][k],a[j] * a[i] * a[k] + dp[i][j] + dp[j][i + len]);
}
}
}
printf("%d\n", dp[0][n - 1]);
}
return 0;
}
poj 1651
最新推荐文章于 2023-12-29 13:09:48 发布