Pagini recente » Cod sursa (job #3278782) | Cod sursa (job #3278783) | Cod sursa (job #2878904) | Cod sursa (job #2709535) | Cod sursa (job #3237057)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("podm.in");
ofstream cout("podm.out");
int n;
vector<long long> A;
long long dp[503][503];
int main()
{
cin>>n;
A.resize(n+1);
for(int i=0;i<=n;i++)
cin>>A[i];
for(int i=n-1;i>=1;i--)
for(int j=i+1;j<=n;j++)
{
dp[i][j]=999999999999999999;
//cout<<dp[i][j]<<" ";
for(int k=i;k<j;k++)
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+A[i-1]*A[k]*A[j]);
}
cout<<dp[1][n];
return 0;
}