Pagini recente » Cod sursa (job #959897) | Cod sursa (job #2157777) | Cod sursa (job #389914) | Cod sursa (job #430068) | Cod sursa (job #509569)
Cod sursa(job #509569)
#include <fstream>
using namespace std;
const char InFile[]="podm.in";
const char OutFile[]="podm.out";
const unsigned long long MaxN=505;
const unsigned long long INF=(1LL<<60);
ifstream fin(InFile);
ofstream fout(OutFile);
unsigned long long N,d[MaxN],best[MaxN][MaxN];
int main()
{
fin>>N;
for(register int i=0;i<=N;++i)
{
fin>>d[i];
}
fin.close();
for(register int i=1;i<N;++i)
{
best[i][i+1]=d[i-1]*d[i]*d[i+1];
}
for(register int k=2;k<=N;++k)
{
for(register int i=1;i+k<=N;++i)
{
best[i][i+k]=INF;
for(register int j=i;j<i+k;++j)
{
best[i][i+k]=min(best[i][i+k],best[i][j]+best[j+1][i+k]+d[i-1]*d[i+k]*d[j]);
}
}
}
fout<<best[1][N];
fout.close();
return 0;
}