package lily.algorithm;
import org.junit.Test;
import lily.utils.MemoryTest;
public class MatrixMultiply {
@Test
public void test() {
System.out.println(MemoryTest.toMemoryInfo());
int[][] a = {
{1, 2, 3, 4}, {3, 4, 6, 7}, {3, 7, 6, 7}, {3, 2, 4, 8}};
int[][] b = {
{2, 1, 4, 3}, {6, 8, 2, 3}, {3, 4, 6, 7}, {1, 4, 8, 3}};
// int[][] a = {
{1, 2, 3}, {3, 4, 7}, {3, 7, 7}};
// int[][] b = {
{2, 1, 3}, {6, 8, 3}, {3, 4, 7}};
int[][] c = definitionMethod(a, b);
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[0].length; j++) {
System.out.print(c[i][j]);
System.out.print("\t");
}
System.out.println();
}
System.out.println("=======================");
c = divideConqueMethod(a, b);
for (int i = 0; i < c.length; i++) {
for (int j = 0; j < c[0].length; j++) {
System.out.print(c[i][j]);
System.out.print("\t");
}
System.out.println();
}
}
/**
* 矩阵相乘定义
*
* @param a
* @param b
* @return
*/
public int[][] definitionMethod(int[][] a, int[][] b) {
if (a[0].length != b.len
Java实现用传统分治法解决矩阵相乘问题
最新推荐文章于 2021-02-21 06:54:09 发布
本文详细介绍了如何使用Java编程语言,结合传统的分治策略,高效地解决矩阵相乘的问题。通过递归分解,将大问题转化为小问题,从而降低计算复杂度,提高计算效率。
摘要由CSDN通过智能技术生成