Pagini recente » Cod sursa (job #2682053) | Cod sursa (job #1554640) | Cod sursa (job #838440) | Cod sursa (job #2073303) | Cod sursa (job #1931856)
#include <fstream>
using namespace std;
ifstream fin("podm.in");
ofstream fout("podm.out");
unsigned long long d[502],n,i,matrice[502][502],x,k;
int main()
{
fin>>n;
for(i=0; i<=n; i++) fin>>d[i];
for(i=1; i<n; i++)
matrice[i][i+1]=d[i-1]*d[i]*d[i+1];
for(x=2; x<n; x++)
{
for(i=1;i <= n-x ; i++)
{
matrice[i][i+x]=100000000000000000LL;
for(k=i; k < i+x; k++)
{
matrice[i][i+x] = min(matrice[i][i+x], matrice[i][k] + matrice[k+1][i+x] + d[i-1]*d[k]*d[i+x]);
}
}
}
fout<<matrice[1][n];
return 0;
}