标签:
3
2 3 4 5
64
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> using namespace std; const long long maxn = 105,maxint = 98765432123456L; long long n,a[maxn],f[maxn][maxn]; int main(){ cin>>n; for(int i = 1;i <= n+1;i++){ cin>>a[i]; } for(int i = 1;i <= n+1;i++){ for(int j = 1;j <= n+1;j++){ f[i][j] = maxint; } } long long j,tmp; for(int l = 3;l <= n+1;l++){ for(int i = 1;i <= n-1;i++){ j = i + l - 1; for(int k = i + 1;k <= j-1;k++){ tmp = a[i] * a[k] * a[j]; if(k - i >= 2) tmp += f[i][k]; if(j - k >= 2) tmp += f[k][j]; f[i][j] = min(f[i][j],tmp); } } } cout<<f[1][n+1]; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5754649.html