Pagini recente » Monitorul de evaluare | Cod sursa (job #2071556) | Monitorul de evaluare | Rating Cernusca Tudor (Cernusca) | Cod sursa (job #604706)
Cod sursa(job #604706)
#include <iostream>
#define NMax 505
#define Inf 100000000000LL
using namespace std;
long long N, D[NMax], Best[NMax][NMax];
void Read ()
{
freopen ("podm.in", "r", stdin);
scanf ("%lld", &N);
for (int i=1; i<=N+1; ++i)
{
scanf ("%lld", &D[i]);
}
}
void Print ()
{
freopen ("podm.out", "w", stdout);
printf ("%lld\n", Best[1][N]);
}
inline long long Min (long long a, long long b)
{
if (a<b)
{
return a;
}
return b;
}
int main()
{
Read ();
for (long long d=1; d<N; ++d)
{
for (long long i=1; i+d<=N; ++i)
{
long long j=i+d;
Best[i][j]=Inf;
for (long long k=i; k<j; ++k)
{
Best[i][j]=Min (Best[i][j], Best[i][k]+Best[k+1][j]+D[i]*D[k+1]*D[j+1]);
}
}
}
Print ();
return 0;
}