Pagini recente » Cod sursa (job #2345611) | Cod sursa (job #100611) | Cod sursa (job #180272) | Cod sursa (job #1482086) | Cod sursa (job #1576209)
#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];
int back(int start,int stop)
{
int i;
long long minim=MAX;
if(stop-start==0) return 0;
for(i=start+1;i<=stop;i++)
{
minim=min(minim,back(start,i-1)+back(i,stop)+cost[start][i-1][0]*cost[i][stop][1]*cost[i][stop][0]);
}
cost[start][stop][2]=minim;
cost[start][stop][0]=cost[start][start][0];
cost[start][stop][1]=cost[stop][stop][1];
return minim;
}
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<<back(1,n);
}