Pagini recente » Cod sursa (job #2326772) | Cod sursa (job #3167708)
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e6;
const int NMAX = 502;
int n,d[NMAX],dp[NMAX][NMAX];
ifstream fin("podm.in");
ofstream fout("podm.out");
auto minSelf(auto &a, auto b){
a = min(a, b);
}
int main()
{
fin >> n;
n++;
for(int i = 1; i <= n; i++){
fin >> d[i];
dp[i][i+1] = 0;
}
for(int len = 3; len <= n; len++){
for(int l = 1; l <= n-len+1; l++){
int r = l+len-1;
dp[l][r] = INF;
for(int k = l+1; k < r; k++){
minSelf(dp[l][r], dp[l][k]+dp[k][r]+d[l]*d[k]*d[r]);
}
}
}
fout << dp[1][n];
return 0;
}