Pagini recente » Cod sursa (job #1420704) | Cod sursa (job #8822) | Cod sursa (job #1633094) | Cod sursa (job #2195472) | Cod sursa (job #2195152)
#include <fstream>
#include <iomanip>
using namespace std;
ifstream cin("podm.in");
ofstream cout("podm.out");
const int MAX = 501;
const long long INF = (1ll << 62);
int v[MAX], n;
long long dp[MAX][MAX];
int main()
{
cin >> n;
for(int i = 0; i <= n; ++i)
cin >> v[i];
for(int d = 2; d <= n; ++d) {
for(int i = 1, j = d; j <= n; ++i, ++j) {
dp[i][j] = INF;
for(int k = i + 1; k <= j; ++k)
dp[i][j] = min(dp[i][j], dp[i][k - 1] + dp[k][j] + 1ll * v[i - 1] * v[k - 1] * v[j]);
}
}
cout << dp[1][n];
return 0;
}