Pagini recente » Cod sursa (job #2896396) | Cod sursa (job #218210) | Cod sursa (job #2923141) | Cod sursa (job #2055301) | Cod sursa (job #1222565)
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define MAX 505
struct Matrix{
int X, Y;
Matrix(){
}
Matrix(int X, int Y) {
this->X = X, this->Y = Y;
}
} M[MAX];
int N;
unsigned long long Best[MAX][MAX], B;
int main() {
int X, Y;
freopen("podm.in","r",stdin);
freopen("podm.out","w",stdout);
scanf("%d", &N);
scanf("%d", &X);
for (int i = 1; i <= N; i++) {
scanf("%d", &Y);
M[i] = Matrix(X,Y);
X=Y;
}
for (int j = 2; j <= N; j++)
for (int i = 1; i <= N - j + 1; i++) {
for (int k = i; k < j + i - 1; k++) {
B = Best[i][k] + Best[k+1][j+i-1] + M[i].X * M[k].Y * M[j+i-1].Y;
if (Best[i][j+i-1] == 0 || (B < Best[i][j+i-1])) {
Best[i][j+i-1] = B;
}
}
}
cout << Best[1][N];
return 0;
}