26 条题解
-
-1tobright LV 10 @ 2009-08-01 08:44:57
前面有这样的题目了,这题目重复了
。。。。。。。。 -
-12009-07-31 18:16:43@
裸的矩阵*,模版就是给你的那个图,都不用构造
-
-12009-07-31 15:54:16@
矩阵A=a*b
矩阵B=b*c
矩阵c=a*c矩阵A*矩阵B,运算法则为:
for (i=1;i
-
-12009-07-31 14:27:47@
矩阵乘法
-
-12009-07-31 17:19:00@
和DOMINO那题很像,比那还简单
o(n^3logm) -
-22015-11-05 21:23:07@
如楼上所说,非常巧妙的一道**矩阵乘法题**。其实就是读入的初始矩阵的m次幂, 快速幂解之。C++定义个类,重载一下运算符可以让代码更工整哦!
#BLOCK CODE
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;const int maxn = 60;
typedef struct MATRIX {/*定义矩阵类*/
int row, column, mod;
int matrix[maxn][maxn];
MATRIX() {column = row = 0; mod = 100007; memset(matrix, 0, sizeof(matrix));};
void In(int x) {column = row = x; for (int i = 0; i < x; i++) matrix[i][i] = 1;};
MATRIX operator*(const MATRIX b) const {/*重载乘号*/
MATRIX c;
c.row = row; c.column = b.column; c.mod = mod;
for (int i = 0; i < row; i++)
for (int j = 0; j < b.column; j++)
for (int k = 0; k < column; k++){
c.matrix[i][j] += matrix[i][k] * b.matrix[k][j] % mod;/*记得要取模*/
c.matrix[i][j] %= mod;
}return c;
}
} mat;mat a;
int n, m, s, f, p;mat fast_power(const mat x, int y) {/*快速幂*/
mat ans, tmp;
ans.In(n); tmp = x; ans.mod = p;/*<- 一定不要忘了把模数改成 p,否则死的很惨。*/
while (y) {
if (y & 1)
ans = ans * tmp;
tmp = tmp * tmp;
y >>= 1;
}
return ans;
}void read(int &x) {/*读入优化*/
char chr = getchar();
x = 0;
while (!isdigit(chr))
chr = getchar();
while (isdigit(chr)) {
x *= 10; x += chr - 48;
chr = getchar();
}
}int main() {
//freopen("input.txt", "r", stdin);
read(n);
a.row = n; a. column = n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++){
read(a.matrix[i][j]);
}
read(m); read(s); read(f); read(p);
a.mod = p;
a = fast_power(a, m);
printf("%d\n", a.matrix[s-1][f-1] % p);
//fclose(stdin);
return 0;
}