Pagini recente » Cod sursa (job #2093110) | Cod sursa (job #687207) | Cod sursa (job #2641222) | Cod sursa (job #788067) | Cod sursa (job #1494389)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 501;
long long best[nmax][nmax], d[nmax];
int main()
{
freopen("podm.in", "r", stdin);
freopen("podm.out", "w", stdout);
int n, i, j, k, x;
scanf("%d ", &n);
for(i=0; i<=n; i++)
scanf("%d ", &d[i]);
for(i=1; i<n; i++)
best[i][i+1]=d[i-1]*d[i]*d[i+1];
for(i=2; i<n; i++)
for(j=1; j<=n-i; j++)
{
x=i+j;
best[j][x]=INFINITY;
for(k=j; k<=x-1; k++)
best[j][x]=min(best[j][x],best[j][k]+best[k+1][x]+d[j-1]*d[k]*d[x]);
}
printf("%lld",best[1][n]);
fclose(stdin);
fclose(stdout);
return 0;
}