标签:
6
10 1 50 50 20 5
3650
/* 枚举区间内最后一个乘数 */ #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #define ll long long using namespace std; const int maxn = 125; const ll inf = 987654321234LL; ll read(){ char ch=getchar(); ll x=0,f=1; while(!(ch>=‘0‘&&ch<=‘9‘)){if(ch==‘-‘)f=-1;ch=getchar();}; while(ch>=‘0‘&&ch<=‘9‘){x=x*10+(ch-‘0‘);ch=getchar();}; return x*f; } int n; ll a[maxn],dp[maxn][maxn]; int main(){ n = read(); for(int i = 1;i <= n;i++) a[i] = read(); for(int i = 0;i <= n;i++){ for(int j = 0;j <= n;j++){ dp[i][j] = inf; } } for(int i = 1;i < n;i++){ dp[i][i+1] = 0; } int j; for(int l = 3;l <= n;l++){ for(int i = 1;i <= n-l+1;i++){ j = i + l - 1; for(int k = i + 1;k <= j-1;k++){ dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j] + a[i]*a[k]*a[j]); } } } cout<<dp[1][n]; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5925013.html