Pagini recente » Cod sursa (job #1355204) | Cod sursa (job #64614) | Cod sursa (job #851787) | Cod sursa (job #2461774) | Cod sursa (job #1803359)
#include <fstream>
#include <climits>
using namespace std;
unsigned short int n;
unsigned short int d[501];
unsigned long long int best[501][501];
unsigned short int i, j, k, w;
unsigned long long int sol;
int main ()
{
ifstream fin ("podm.in");
fin >> n;
for (i=0; i<=n; i++)
fin >> d[i];
fin.close();
for (i=1; i<=n-1; i++)
best[i][i+1] = d[i-1] * d[i] * d[i+1];
for (w=2; w<=n-1; w++)
for (i=1; i<=n-w; i++)
{
j = i + w;
best[i][j] = ULLONG_MAX;
for (k=i; k<=j-1; k++)
best[i][j] = min(best[i][j],best[i][k]+best[k+1][j]+d[i-1]*d[k]*d[j]);
}
sol = best[1][n];
ofstream fout ("podm.out");
fout << sol;
fout.close();
return 0;
}