Pagini recente » Cod sursa (job #324793) | Cod sursa (job #2114817) | Cod sursa (job #2676696) | Cod sursa (job #2814490) | Cod sursa (job #525123)
Cod sursa(job #525123)
#include<fstream>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
long long c[1002][1002], d[1002];
int n;
void PD_mixt();
void read();
void write();
int main()
{
read();
PD_mixt();
write();
return 0;
}
void read()
{
ifstream fin("podm.in");
fin >> n;
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
c[i][j] = INF;
for(int i = 0; i <= n; ++i)
fin >> d[i];
fin.close();
}
void write()
{
ofstream fout("podm.out");
fout << c[1][n] ;
fout.close();
}
void PD_mixt()
{
for(int i = 1; i <= n; ++i)
c[i][i] = 0;
for(int L = 1; L <= n; ++L )
for(int i = 1; i <= n; ++i)
{
int j = i + L;
for(int k = i; k < j; ++k)
c[i][j] = min (c[i][j], c[i][k] + c[k+1][j] + d[i-1]*d[j]*d[k] );
}
}