Cod sursa(job #2213232)

Utilizator unknownpersonBidasca Carina Georgiana unknownperson Data 15 iunie 2018 20:40:37
Problema Parantezare optima de matrici Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include<bits/stdc++.h>
#define UPD(s,m,d) BST[s][m]+BST[m][d]+x[s]*x[m]*x[d]
using namespace std;
ifstream f("podm.in");
ofstream g("podm.out");
int n,i,LG,ST,DR,MI;
long long x[501],BST[501][501],Bst,bst;
int main()
{
    f>>n;
    for(i=0;i<=n;i++)
        f>>x[i];
    for(LG=2;LG<=n;LG++)
    {
        for(ST=0,DR=LG;DR<=n;ST++,DR++)
        {
            MI=ST+1;
    BST[ST][DR]=UPD(ST,ST+1,DR);
            for(;MI<DR;MI++)
                BST[ST][DR]=min(BST[ST][DR],UPD(ST,MI,DR));
        }
    }
    g<<BST[0][n];
    return 0;
}