紧急求救!!!!

飒然 2007-08-05 03:14:33
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;
}
}
}
if (p!=0) break;
}
if (p!=0) System.out.println("NO");
else System.out.println("YES");
}
}
...全文
136 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiukaijia 2010-04-08
  • 打赏
  • 举报
回复
TLE,超时,o(n^3)了
zdjray 2007-08-08
  • 打赏
  • 举报
回复
推荐先看线性代数

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧