声明一个矩阵类,求两个矩阵的积

来源:百度知道 编辑:UC知道 时间:2024/05/29 03:10:32
求原代码

import javax.swing.*;
import java.lang.*;
public class TestStrassen{
public static int[][] strassen(int[][]A,int[][]B){
int [][]C=new int [A.length][A.length];
if(A.length==2){
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++){C[i][j]+=A[i][k]+B[k][j];}
return C;
}
else{
int [][]A11=new int [A.length/2][A.length/2];
int [][]A12=new int [A.length/2][A.length/2];
int [][]A21=new int [A.length/2][A.length/2];
int [][]A22=new int [A.length/2][A.length/2];
int [][]B11=new int [A.length/2][A.length/2];
int [][]B12=new int [A.length/2][A.length/2];
int [][]B21=new int [A.length/2][A.length/2];
int [][]B22=new int [A.length/2][A.length/2];
//定义中间变量
int [][]M1=new int [A.length/2][A.length/2];
int [][]M2=new int [A.length/2][A.length/2];
int [][]M3=new int [A.length/2][A.length/2];
int [][