formatting source-code for 153fb7b8a5

This commit is contained in:
github-actions
2020-05-30 04:02:09 +00:00
parent 92fe9495ec
commit 8a2de9842b
175 changed files with 1671 additions and 3460 deletions

View File

@@ -9,8 +9,7 @@ int dp[MAX][MAX];
// Function to find the most efficient way to multiply the given sequence of
// matrices
int MatrixChainMultiplication(int dim[], int i, int j)
{
int MatrixChainMultiplication(int dim[], int i, int j) {
// base case: one matrix
if (j <= i + 1)
return 0;
@@ -21,13 +20,11 @@ int MatrixChainMultiplication(int dim[], int i, int j)
// if dp[i][j] is not calculated (calculate it!!)
if (dp[i][j] == 0)
{
if (dp[i][j] == 0) {
// take the minimum over each possible position at which the
// sequence of matrices can be split
for (int k = i + 1; k <= j - 1; k++)
{
for (int k = i + 1; k <= j - 1; k++) {
// recur for M[i+1]..M[k] to get a i x k matrix
int cost = MatrixChainMultiplication(dim, i, k);
@@ -48,8 +45,7 @@ int MatrixChainMultiplication(int dim[], int i, int j)
}
// main function
int main()
{
int main() {
// Matrix i has Dimensions dim[i-1] & dim[i] for i=1..n
// input is 10 x 30 matrix, 30 x 5 matrix, 5 x 60 matrix
int dim[] = {10, 30, 5, 60};