Pagini recente » Cod sursa (job #2492730) | Cod sursa (job #1725951) | Cod sursa (job #1316896) | Cod sursa (job #1194704) | Cod sursa (job #2409798)
#include <fstream>
using namespace std;
ifstream cin ("podm.in");
ofstream cout ("podm.out");
const int LIM = 505;
int n, d[LIM], dp[LIM][LIM];
void print()
{
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
cout << dp[i][j] << ' ';
cout << '\n';
}
}
int main()
{
cin >> n;
for (int i = 0; i <= n; ++i)
cin >> d[i];
for (int i = 2; i <= n; ++i)
for (int x = 1, y = i; y <= n; ++x, ++y)
{
dp[x][y] = (1 << 31) - 1;
for (int j = x; j < y; ++j)
dp[x][y] = min(dp[x][y], dp[x][j] + dp[j + 1][y] + d[x - 1] * d[j] * d[y]);
}
//print();
cout << dp[1][n];
return 0;
}