日期:2014-05-20  浏览次数:20632 次

紧急求救!!!!
Description


You   are   given   three   n   ×   n   matrices   A,   B   and   C.   Does   the   equation   A   ×   B   =   C   hold   true?


Input


The   first   line   of   input   contains   a   positive   integer   n   (n   ≤   500)   followed   by   the   the   three   matrices   A,   B   and   C   respectively.   Each   matrix 's   description   is   a   block   of   n   ×   n   integers.

It   guarantees   that   the   elements   of   A   and   B   are   less   than   100   in   absolute   value   and   elements   of   C   are   less   than   10,000,000   in   absolute   value.


Output


Output   "YES "   if   the   equation   holds   true,   otherwise   "NO ".


Sample   Input


2
1   0
2   3
5   1
0   8
5   1
10   26


Sample   Output


YES
我的程序:这是矩阵相乘的问题,谁有高效算法吗???求救啊
import   java.util.*;

public   class   Main1{
        public   static   void   main(String[]   args){
              Scanner   s   =   new   Scanner(System.in);
              int   n   =   s.nextInt();
              int   k   =   3*n;
              int[][]   a   =   new   int[k][k];
              int   p   =   0;
              for   (int   j   =   0;j   <   k;j++){
                      for(int   m   =   0;   m   <   n;m++){
                                    a[j][m]   =   s.nextInt();
                                    if   (j   >   2*n){
                                          int   q   =   0;
                                          for(int   e   =   0;e   <   n;e++){
                                              q   =   q+a[j-2*n][e]*a[e+n][m];
                                          }
                                          if   (a[j][m]!=q){
                                                p++;break;