Cod sursa(job #1971070)

Utilizator radu.leonardoThe Doctor radu.leonardo Data 19 aprilie 2017 20:01:07
Problema Parantezare optima de matrici Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("podm.in");
ofstream g("podm.out");

int N;
long long V[501],DP[501][501];

int main()
{
    f>>N;
    for(int i=0;i<=N; ++i) f>>V[i];

    for(int i=1;i<N; ++i)
        for(int j=i+1; j<=N; ++j)
        {
            DP[j-i][j]=1LL<<60;
            for(int k=j-i; k<j; ++k)
                DP[j-i][j]=min(DP[j-i][j],DP[j-i][k]+DP[k+1][j]+V[j-i-1]*V[k]*V[j]);
        }
    g<<DP[1][N];
}