Pagini recente » Cod sursa (job #558033) | Cod sursa (job #2337980) | Cod sursa (job #2464676) | Cod sursa (job #2151193) | Cod sursa (job #3167593)
#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const char sp = ' ';
const int inf = 0x3f3f3f3f;
const long long INF = 1000000000000000000;
const int mod = 1e9 + 7;
const char out[2][4]{ "NO", "YES" };
#define all(A) A.begin(), A.end()
using ll = long long;
ifstream fin("podm.in");
ofstream fout("podm.out");
#define variableName(var) #var
#define __debug(var) cout << #var << " = " << var << '\n'
inline int rint(int a, int b) { return uniform_int_distribution<int>(a, b)(rng); }
const int nmax = 500;
int n;
ll v[nmax + 5]{ 0 };
ll dp[nmax + 5][nmax + 5]{ 0 };
bool vis[nmax + 5][nmax + 5]{ 0 };
void solve(int l, int r) {
if (vis[l][r]) {
return;
}
vis[l][r] = true;
if (l == r) {
return;
}
dp[l][r] = INF;
for (int k = l; k < r; ++k) {
solve(l, k);
solve(k + 1, r);
dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + v[l] * v[k + 1] * v[r + 1]);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
fin >> n;
for (int i = 1; i <= n + 1; ++i) {
fin >> v[i];
}
solve(1, n);
fout << dp[1][n];
}