一种奇葩的写法,纪念一下当时的RE。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <cctype>
#include <time.h> using namespace std; const int INF = <<;
const int MAXN = ; struct Matrix {
int a[MAXN][MAXN];
int col, row;
}; Matrix tMu; void multiplication(const Matrix &x, const Matrix &y) {
tMu.row= x.row; tMu.col = y.col;
for (int i = ; i < tMu.row; i++)
for (int j = ; j < tMu.row; j++) {
tMu.a[i][j] = ;
for (int k = ; k < x.col; k++)
tMu.a[i][j] = (tMu.a[i][j]+x.a[i][k]*y.a[k][j])%;
}
} Matrix a, b, ONE;
Matrix t;
Matrix tmp, res; int n, k; void pow(const Matrix &x, int d) {
res = ONE; res.col = res.row = x.col;
tmp = x;
while (d>) {
if (d&) {
multiplication(res, tmp);
res = tMu;
}
multiplication(tmp, tmp);
tmp = tMu;
d >>= ;
}
} void solve() {
multiplication(b, a);
t = tMu;
pow(t, n*n-);
t = res;
multiplication(a, t);
t = tMu;
multiplication(t, b);
t = tMu;
int ans = ;
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++)
ans += t.a[i][j];
}
printf("%d\n", ans);
} int main() {
#ifdef Phantom01
freopen("HDU4965.txt", "r", stdin);
#endif //Phantom01 for (int i = ; i < MAXN; i++) {
for (int j = ; j < MAXN; j++)
ONE.a[i][j] = ;
ONE.a[i][i] = ;
} while (scanf("%d%d", &n, &k)!=EOF && !(n==&&k==)) {
a.row = b.col = n;
a.col = b.row = k;
for (int i = ; i < n; i++)
for (int j = ; j < k; j++)
scanf("%d", &a.a[i][j]);
for (int i = ; i < k; i++)
for (int j = ; j < n; j++)
scanf("%d", &b.a[i][j]);
solve();
} return ;
}

HDU 4965 Fast Matrix Calculation 矩阵乘法 乘法结合律的更多相关文章

  1. hdu 4965 Fast Matrix Calculation(矩阵高速幂)

    题目链接.hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N. 矩阵C = A*B 矩阵M=CN∗N 将矩阵M中的全部元素取模6,得到 ...

  2. HDU 4965 Fast Matrix Calculation 矩阵快速幂

    题意: 给出一个\(n \times k\)的矩阵\(A\)和一个\(k \times n\)的矩阵\(B\),其中\(4 \leq N \leq 1000, \, 2 \leq K \leq 6\) ...

  3. HDU 4965 Fast Matrix Calculation(矩阵高速幂)

    HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个 ...

  4. HDU4965 Fast Matrix Calculation —— 矩阵乘法、快速幂

    题目链接:https://vjudge.net/problem/HDU-4965 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Othe ...

  5. hdu 4965 Fast Matrix Calculation

    题目链接:hdu 4965,题目大意:给你一个 n*k 的矩阵 A 和一个 k*n 的矩阵 B,定义矩阵 C= A*B,然后矩阵 M= C^(n*n),矩阵中一切元素皆 mod 6,最后求出 M 中所 ...

  6. HDU - 4965 Fast Matrix Calculation 【矩阵快速幂】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4965 题意 给出两个矩阵 一个A: n * k 一个B: k * n C = A * B M = (A ...

  7. hdu4965 Fast Matrix Calculation 矩阵快速幂

    One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learni ...

  8. Fast Matrix Calculation 矩阵快速幂

    One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learni ...

  9. hdu4965 Fast Matrix Calculation (矩阵快速幂 结合律

    http://acm.hdu.edu.cn/showproblem.php?pid=4965 2014 Multi-University Training Contest 9 1006 Fast Ma ...

随机推荐

  1. Day 01 计算机编程基础

    1.编程语言是什么? 编程语言是人与计算机交流的介质 2.什么是编程? 用编程语言写出一个个文件,这堆文件会达到一个目的 3.编程有什么用? 让计算机帮助我们干活,从而解放人类劳动力 4.计算机组成原 ...

  2. python之类与对象的属性

    类相关的知识 在python2中的区分: 经典类: class School: pass 新式类: class School(object): pass 在python3中以上两种均为新式类 属性: ...

  3. js数组的一些骚操作 (用一行代码实现)

    1.扁平化n维数组 1.终极篇 [1,[2,3]].flat(2) //[1,2,3] [1,[2,3,[4,5]].flat(3) //[1,2,3,4,5] [1[2,3,[4,5[...]].f ...

  4. BZOJ 3510 首都 (LCT)

    洛谷P4299传送门 题目大意:给你一颗树,边是一条一条连上去的 在连接过程中会存在询问,询问当前节点所在联通块(其实是一颗树)的重心是哪个节点 以及森林中所有树的重心的异或和 在做这道题之前,要先了 ...

  5. mkl安装与使用

    mkl安装教程 1.下载 首先到该网站下载压缩包,需要注册 2.安装 首先解压缩 tar -zxvf l_mkl_2019.0.117.tgz 进入目录进行安装 cd l_mkl_2019.0.117 ...

  6. MD5加密技术

    前几天,在看OpenVXI3.4的时候,偶然发现了几个奇怪的文件,那就是OpenVXI-3.4\src\cache下面的,base64.c,base64.h,md5.c,md5.h.既然有人把源代码给 ...

  7. ZJU 2671 Cryptography

    Cryptography Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...

  8. android自己定义Application全局变量不能类型转换的问题

    今天弄了个全局变量AppContext ,但一直出现例如以下错误,原来继承 Application的得在清单文件声明. java.lang.RuntimeException: Unable to st ...

  9. MyEclipse2014高速配置Spring &amp; Spring Testing, Spring AOP简单使用

    1.新建项目 2.右击项目,如图,利用myeclipse自己主动导入spring 3.在弹出的对话框中一直next到最后,在最后的页面中勾选Spring Testing,完毕. watermark/2 ...

  10. 使用excel进行数据挖掘(6)---- 预測

    在配置环境后,能够使用excel进行数据挖掘. 环境配置问题可參阅: http://blog.csdn.net/xinxing__8185/article/details/46445435 例子 DM ...