Mai intai trebuie sa te autentifici.
Cod sursa(job #1643612)
| Utilizator | Data | 9 martie 2016 19:31:57 | |
|---|---|---|---|
| Problema | Parantezare optima de matrici | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("podm.in");
ofstream g("podm.out");
long long oo = 100000000000000LL;
const int Nmax = 510;
long long DP[Nmax][Nmax];
int d[Nmax],n;
void Solve()
{
for(int step = 1; step < n; step++)
{
for(int i = 1; i <= n-step; i++)
{
int j = step+i;
DP[i][j] = oo;
for(int k = i; k < j; k++)
{
DP[i][j] = min(DP[i][j], DP[i][k]+DP[k+1][j]+1LL*d[i-1]*d[j]*d[k]);
}
}
}
}
int main()
{
f>>n;
for(int i = 0; i <= n; i++) f>>d[i];
Solve();
g<<DP[1][n];
return 0;
}
