Cod sursa(job #787356)

Utilizator NicuCJNicu B. NicuCJ Data 13 septembrie 2012 11:09:49
Problema Parantezare optima de matrici Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
// CasketOfStar.cpp : Defines the entry point for the console application.
//

#include <fstream>

using namespace std;

long long m[501][501], d[502];

long long sol(int i, int j)
{
	if(i==j) return 0;
	int k;
	m[i][j]=1000000000000000LL;
	for(k=i; k<j; k++)
	{
		m[i][j]=min(m[i][j], sol(i, k)+sol(k+1, j)+d[i-1]*d[k]*d[j]);
	}
	return m[i][j];
}

int main()
{
	int i, n;
	ifstream f("podm.in");
	ofstream g("podm.out");
	f>>n;
	for(i=0; i<=n; i++)
	{
		f>>d[i];
	}
	g<<sol(1, n);
}