Pagini recente » Cod sursa (job #577766) | Cod sursa (job #1723029) | Cod sursa (job #2976671) | Cod sursa (job #185403) | Cod sursa (job #2380707)
#include <bits/stdc++.h>
using namespace std;
ifstream f("podm.in");
ofstream g("podm.out");
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define INF 100000000000000000LL
long long bst[505][505],d[505];
int n;
int main()
{
f>>n;
for(int i=0;i<=n;i++)
f>>d[i];
for(int i=1;i<=n;i++)
bst[i][i]=0;
for(int i=1;i<n;i++)
bst[i][i+1]=d[i-1]*d[i]*d[i+1];
for(int e=2; e<n;e++)
for(int i=1; i<=n - e; i++)
{
int j = i + e;
bst[i][j] = INF;
for(int k=i;k<j;k++)
bst[i][j] = Min(bst[i][j], bst[i][k] + bst[k + 1][j] + d[i - 1] * d[k] * d[j]);
}
g<<bst[1][n];
}