#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,a[105],
dp[105][105], i, j, k, l;
int main(){
//freopen("data.in", "r", stdin);
while(~scanf("%d",&n)){
for(i = 1; i <= n; i++)
scanf("%d", &a[i]);
memset(dp, 0x3f3f3f3f, sizeof(dp));
for(int i = 1; i <= n; i++)//1张牌没意义
dp[i][i] = 0;
for(l = 2; l <= n-1; l++){//长度从2开始枚举,最后一张牌不能动
for(i = 2; i <= n-l+1; i++){
j = i+l-1;
dp[i][j] = 0x3f3f3f3f;
for(k = i; k < j; k++)//枚举中点
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+a[i-1]*a[k]*a[j]);
}
}
printf("%d\n",dp[2][n]);
}
return 0;
}
POJ 1651 Multiplication Puzzle(区间DP)
最新推荐文章于 2023-12-29 13:09:48 发布