Pagini recente » Cod sursa (job #78365) | Cod sursa (job #235723) | Cod sursa (job #500323) | Cod sursa (job #44380) | Cod sursa (job #2879172)
#include <fstream>
typedef long long int ullint;
ullint vec[505];
ullint dp[505][505];
int main() {
std::ifstream fin("podm.in");
std::ofstream fout("podm.out");
int nrn;
fin >> nrn;
for (int index = 0; index <= nrn; index++) {
fin >> vec[index];
dp[index][index] = 0;
}
for (int pos1 = nrn - 2; pos1 >= 0; pos1--) {
for (int pos2 = pos1 + 1; pos2 < nrn; pos2++) {
dp[pos1][pos2] = 0x7fffffff;
for (int posm = pos1; posm < pos2; posm++) {
dp[pos1][pos2] = std::min(dp[pos1][pos2], dp[pos1][posm] + dp[posm + 1][pos2] + vec[pos1] * vec[posm + 1] * vec[pos2 + 1]);
}
}
}
fout << dp[0][nrn - 1];
return 0;
}