Pagini recente » Cod sursa (job #1806265) | Cod sursa (job #1259424) | Cod sursa (job #2021011) | Cod sursa (job #99976) | Cod sursa (job #1576674)
#include<iostream>
#include<fstream>
#define MAX 1000000000000000000
using namespace std;
fstream fin("podm.in",ios::in),fout("podm.out",ios::out);
long long n,cost[510][510][3],minim;
int solv()
{
int start,stop,i;
for(start=n;start>0;start--)
{
for(stop=start+1;stop<=n;stop++)
{
minim=MAX;
for(i=start+1;i<=stop;i++)
{ //$a $b xa xb yb
minim=min(minim,cost[start][i-1][2]+cost[i][stop][2]+cost[start][i-1][0]*cost[i][stop][0]*cost[i][stop][1]);
}
cost[start][stop][2]=minim;
cost[start][stop][0]=cost[start][start][0];
cost[start][stop][1]=cost[stop][stop][1];
}
}
return cost[1][n][2];
}
int main()
{
int i,j,pre,act;
fin>>n;
fin>>pre;
for(i=1;i<=n;i++)
{
fin>>act;
cost[i][i][0]=pre;
cost[i][i][1]=act;
pre=act;
}
fout<<solv();
}