1. 程式人生 > >Tyvj-OJ-p1014 乘法遊戲

Tyvj-OJ-p1014 乘法遊戲

/****************************************/
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <algorithm>
 #include <cmath>
 #include <stack>
 #include <queue>
 #include <vector>
 #include <map>
 #include <string>
 #include <iostream>
 using namespace std;
/****************************************/
const int N = 105, SUP = 2e9;
int sq[N], n;
int d[N][N];

int DFS(int st, int ed)
{
	if(~d[st][ed])
		return d[st][ed];
	if(st+1 == ed)
		return 0;
	int ret = SUP;
	for(int i = st+1; i <= ed-1; i++)
		ret = min(ret, DFS(st, i) + DFS(i, ed) + sq[st] * sq[i] * sq[ed]);
	return d[st][ed] = ret;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &sq[i]);
	memset(d, -1, sizeof(d));
	printf("%d\n", DFS(1, n));
	return 0;
}