###### 算法导论示例-MatrixChain
/**
* Introduction to Algorithms, Second Edition
* 15.2 Matrix-chain multiplication
* @author 土豆爸爸
*
*/
public class MatrixChain {
public static int[][] order(int[] p) {
int n = p.length - 1;
int[][] m = new int[p.length][p.length];
int[][] s = new int[p.length][p.length];
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = Integer.MAX_VALUE;
for (int k = i; k < j; k++) {
int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
if (q < m[i][j]) {
m[i][j] = q;
s[i][j] = k;
}
}
}
}
return s;
}
}

import junit.framework.TestCase;

public class MatrixChainTest extends TestCase {
public void testMatrixChain() {
int[] p = {30, 35, 15, 5, 10, 20 ,25};
int[][] s = MatrixChain.order(p);
print(s, 1, 6);
}

public void print(int[][] s, int i, int j) {
if(i == j) {
System.out.print("A" + i);
} else {
System.out.print("(");
print(s, i, s[i][j]);
print(s, s[i][j] + 1, j);
System.out.print(")");
}
}
}


#### Matrix-chain product 矩阵链乘积

2015-07-01 14:24:51

#### 矩阵链乘法问题描述(Matrix-chain multiplication)

2015-09-13 14:44:32

#### 算法之动态规划-矩阵链相乘（matrix-chain multiplication）

2016-04-07 22:38:41

#### 动态规划 (Dynamic Programming) 之 矩阵链乘法(Matrix Chain Multiplication)

2009-02-27 15:36:00

#### C++作业9.|Matrix chain multiplication

2016-11-29 19:14:59

#### 0010算法笔记——【动态规划】矩阵连乘问题

2013-01-13 20:09:17

#### 算法上机！！

2013年05月30日 16.54MB 下载

#### POJ-2246-Matrix Chain Multiplication

2013-07-27 13:23:42

#### Matrix Chain Multiplication

2006-05-18 00:22:00

#### 动态规划之矩阵链乘法-matrix-chain muliplication problem(dp)

2018-03-10 10:06:35