Pagini recente » Cod sursa (job #1949328) | Cod sursa (job #3285052) | Viata de dupa olimpiade? (I) - Mediul academic | Cod sursa (job #3285225)
#include <fstream>
#define inf 1e18
using namespace std;
ifstream cin("podm.in");
ofstream cout("podm.out");
int n,v[505];
long long dp[505][505];
signed main()
{
cin>>n;
for(int i=1;i<=n+1;i++)
cin>>v[i];
for(int i=1;i<n;i++)
dp[i][i+1]=1LL*v[i]*v[i+1]*v[i+2];
for(int l=3;l<=n;l++)
for(int i=1;i<=n-l+1;i++){
int j=i+l-1;
dp[i][j]=inf;
for(int k=i;k<j;k++)
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+1LL*v[i]*v[k+1]*v[j+1]);
}
cout<<dp[1][n];
return 0;
}