Cod sursa(job #1857037)
| Utilizator | Data | 25 ianuarie 2017 19:03:29 | |
|---|---|---|---|
| Problema | Parantezare optima de matrici | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <bits/stdc++.h>
#define Int long long
using namespace std;
ifstream f("podm.in");
ofstream g("podm.out");
Int n,i,L,R,M,d[510],sol[510][510];
int main()
{
f>>n;
for(i=0;i<=n;i++)
f>>d[i];
for(i=2;i<=n;i++)
for(L=1,R=i;R<=n;L++,R++)
{
sol[L][R]=d[L-1]*d[L]*d[L+1]+sol[L+1][R];
for(M=L;M<R;M++)
sol[L][R]=min(sol[L][R],sol[L][M]+sol[M+1][R]+d[L-1]*d[M]*d[R]);
}
g<<sol[1][n];
return 0;
}
