Pagini recente » Cod sursa (job #2526516) | Rezultatele filtrării | Cod sursa (job #2203972) | Cod sursa (job #1049522) | Cod sursa (job #1032897)
#include <fstream>
#include <algorithm>
using namespace std;
long long d[505],c[505][505];
int N;
inline void Read()
{
int i;
ifstream fin("podm.in");
fin>>N;
for(i=0;i<=N;i++)
fin>>d[i];
fin.close();
}
inline void Solve()
{
int i,j,k,pas;
long long x;
for(i=1;i<N;i++)
c[i][i+1]=d[i-1]*d[i]*d[i+1];
for(pas = 3;pas<=N;pas++)
for(i=1;i<=N - pas + 1;i++)
{
j= i+pas-1;
x=10000000000000000LL;
for(k=i;k<j;k++)
x=min(x,c[i][k]+c[k+1][j]+d[i-1]*d[k]*d[j]);
c[i][j]=x;
}
ofstream fout("podm.out");
fout<<c[1][N]<<"\n";
fout.close();
}
int main()
{
Read();
Solve();
return 0;
}