Pagini recente » Cod sursa (job #3285643) | Cod sursa (job #182372) | Cod sursa (job #3203390)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("podm.in");
ofstream cout("podm.out");
int n;
vector<long long> d;
long long dp[502][502];
int main()
{
cin>>n;
d.resize(n+1);
for(int i=0;i<=n;i++)
cin>>d[i];
for(int i=n;i>=1;i--)
{
dp[i][i]=0;
for(int j=i+1;j<=n;j++)
{
dp[i][j]=0x3f3f3f3f;
for(int k=i;k<j;k++)
{
long long s=dp[i][k]+dp[k+1][j]+d[i-1]*d[k]*d[j];
dp[i][j]=min(dp[i][j],s);
}
}
}
cout<<dp[1][n];
return 0;
}