import java.io.*;
public class Main {
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
static int N = 210;
static int[] a = new int[N];
static long[][] dp = new long[N][N];
public static void main(String[] args) throws Exception{
int n = Integer.valueOf(read.readLine());
String[] ss = read.readLine().split(" ");
for(int i = 0; i < n; i++){
a[i] = Integer.valueOf(ss[i]);
a[i + n] = Integer.valueOf(ss[i]);
}
for(int len = 3; len <= n + 1; len ++){
for(int i = 0; i + len - 1 < 2 * n; i++){ //注意 这里i的边界
int j = i + len - 1;
for(int k = i + 1; k < j; k++){
dp[i][j] = Math.max(dp[i][k] + dp[k][j] + a[i] * a[k] * a[j], dp[i][j]);
}
}
}
long max = 0;
for(int i = 0; i < n; i++){
max = Math.max(dp[i][i + n], max);
}
System.out.println(max);
}
}
这道题好像是昨天蓝桥杯倒数第二题,知道是dp,太菜了, 想不出来