Pagini recente » Cod sursa (job #3204557) | Istoria paginii runda/nstr/clasament | Cod sursa (job #2171449) | Cod sursa (job #1623190) | Cod sursa (job #1463576)
#include <fstream>
using namespace std;
ofstream fout("podm.out");
ifstream fin("podm.in");
const int NMAX = 505;
const long long INF = 10000000000000000LL;
int n;
long long mat[NMAX][NMAX], s[NMAX];
int main()
{
fin >> n;
for(int i=0; i<=n; i++) fin >> s[i];
for(int i=1; i<=n; i++) mat[i][i] = 0;
for(int i=1; i<=n-1; i++) mat[i][i+1] = s[i-1] * s[i] * s[i+1];
for(int d=2; d<=n-1; d++) {
for(int i=1; i<=n-d; i++) {
int j = i + d;
mat[i][j] = INF;
for(int k=i; k<=j-1; k++)
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k+1][j] + s[i-1] * s[k] * s[j]);
}
}
fout << mat[1][n] << '\n';
return 0;
}