You are viewing a single comment's thread. Return to all comments →
MCM
using namespace std;
int minMatrixMultiplicationCost(vector& N) { int n = N.size() - 1; vector> dp(n, vector(n, INT_MAX));
for (int i = 0; i < n; i++) dp[i][i] = 0; for (int length = 2; length <= n; length++) { for (int i = 0; i < n - length + 1; i++) { int j = i + length - 1; for (int k = i; k < j; k++) { int cost = dp[i][k] + dp[k + 1][j] + N[i] * N[k + 1] * N[j + 1]; dp[i][j] = min(dp[i][j], cost); } } } return dp[0][n - 1];
}
int main() { int n; cin >> n;
vector<int> N(n + 1); for (int i = 0; i <= n; i++) cin >> N[i]; cout << minMatrixMultiplicationCost(N) << endl; return 0;
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Tree
You are viewing a single comment's thread. Return to all comments →
MCM
include
include
include
using namespace std;
int minMatrixMultiplicationCost(vector& N) { int n = N.size() - 1; vector> dp(n, vector(n, INT_MAX));
}
int main() { int n; cin >> n;
}