yifan666
-
C,
pasted
on Aug 10:
|
// maze
package MatrixProduct;
import java.io.FileInputStream;
import java.util.Scanner;
public class Solution {
public Scanner sc;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
System.setIn(new FileInputStream("src/MatrixProduct/data"));
new Solution();
}
public int T = 0;
public int length = 0;
public long[][] A;
public int M = 0;
public long q = 100000007;
public Solution() {
sc = new Scanner(System.in);
T = sc.nextInt();
for (int tc = 1; tc <= T; tc++) {
length = sc.nextInt();
A = new long[length][length];
M = sc.nextInt();
for (int row = 0; row < length; row++) {
for(int col = 0; col<length; col++){
A[row][col] = sc.nextInt();
}
}
long [][] a = Mu(A, M);
System.out.println("Case #" + tc);
for (int row = 0; row < length; row++) {
for(int col = 0; col<length; col++){
System.out.print(a[row][col]+" ");
}
System.out.println("");
}
// System.out.println("");
}
}
public long[][] Mu(long[][] a, int m) {
if(m == 1)
return a;
if (m == 2)
return Nhan(a, a);
else {
long[][] c = Mu(a, m / 2);
c = Mu(c, 2);
if (m % 2 != 0) {
return Nhan(a, c);
} else {
return c;
}
}
}
public long[][] Nhan(long[][] a, long[][] b) {
long[][] c = new long[length][length];
long total = 0;
for (int row = 0; row < length; row++) {
for (int col = 0; col < length; col++) {
total = 0;
for (int n = 0; n < length; n++) {
total += (a[row][n] * b[n][col])%q;
}
c[row][col] = total%q;
}
}
return c;
}
}
|
Output:
|
Line 2: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'MatrixProduct'
Line 4: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'java'
Line 5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'java'
Line 7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'class'
|
|