Pagini recente » Cod sursa (job #356344) | Cod sursa (job #267432) | Cod sursa (job #439655) | Cod sursa (job #1079037) | Cod sursa (job #2948895)
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using namespace std;
const int NMAX = 505;
/*******************************/
// INPUT / OUTPUT
ifstream f("podm.in");
ofstream g("podm.out");
/*******************************/
/// GLOBAL DECLARATIONS
int N;
int v[NMAX];
ll dp[NMAX][NMAX];
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> N;
for (int i = 1 ; i <= N + 1 ; ++ i) f >> v[i];
}
///-------------------------------------
inline void Solution()
{
int j;
for (int len = 2 ; len <= N ; ++ len)
{
for (int i = 1 ; i <= N - len + 1 ; ++ i)
{
j = i + len - 1;
dp[i][j] = INT64_MAX;
for (int k = i ; k < j ; ++ k)
{
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + 1LL * v[i] * v[j + 1] * v[k + 1]);
}
}
}
}
///-------------------------------------
inline void Output()
{
g << dp[1][N];
}
///-------------------------------------
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ReadInput();
Solution();
Output();
return 0;
}