Cod sursa(job #2723148)
Utilizator | Data | 13 martie 2021 18:37:05 | |
---|---|---|---|
Problema | Parantezare optima de matrici | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("podm.in");
ofstream g("podm.out");
int n,j,i,st[510],dr[510],d[510][510];
int main()
{
f>>n;
f>>st[1]>>dr[1];
for(i=2;i<=n+1;i++)
{
f>>dr[i];
st[i]=dr[i-1];
}
for(i=n;i>=1;i--)
for(j=1;j<=n;j++)
if(i!=j)d[i][j]=min(d[i+1][j]+st[i]*dr[i]*dr[j], d[i][j-1]+st[i]*st[j]*dr[j]);
g<<d[1][n]<<'\n';
return 0;
}