import java.io.*;
import java.math.*;
import java.util.*;
public class Main{
public static void main(String args[]) {
Scanner cin=new Scanner(System.in);
BigInteger a[]=new BigInteger[105];
BigInteger dp[][]=new BigInteger[105][105];
int n=cin.nextInt();
BigInteger INF =new BigInteger("1000000000000000000000000000000000000000000");
for(int i=1;i<=n;i++) {
a[i]=cin.nextBigInteger();
a[n+i]=a[i];
}
for(int i=1;i<=2*n;i++) {
for(int j=1;j<=2*n;j++) {
dp[i][j]=INF;
}
}
for(int i=1;i<2*n;i++) {
dp[i][i]=dp[i][i+1]=BigInteger.ZERO;
}
for(int i=3;i<=n;i++) {
for(int l=1;l<=2*n-i+1;l++) {
int r=l+i-1;
for(int k=l+1;k<=r-1;k++) {
BigInteger tmp=a[l].multiply(a[k].multiply(a[r]));
tmp=tmp.add(dp[l][k].add(dp[k][r]));
if(tmp.compareTo(dp[l][r])==-1) {
dp[l][r]=tmp;
}
}
}
}
/*for(int i=1;i<=2*n;i++) {
for(int j=1;j<=2*n;j++) {
System.out.println(dp[i][j]);
}
}*/
BigInteger res=new BigInteger("10000000000000000000000000000000000000000000");
for(int i=1;i<=n+1;i++) {
if(dp[i][i+n-1].compareTo(res)==-1) {
res=dp[i][i+n-1];
}
}
System.out.println(res);
}
}
牛客算法周周练9 比赛结束 2020-06-02 19:00:00 至 2020-06-02 21:30:00(E 凸多边形的划分,区间dp+高精度)
最新推荐文章于 2021-05-21 14:20:08 发布