HDU 4965 Fast Matrix Calculation 矩阵乘法 乘法结合律
一种奇葩的写法,纪念一下当时的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 矩阵乘法 乘法结合律的更多相关文章
- hdu 4965 Fast Matrix Calculation(矩阵高速幂)
题目链接.hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N. 矩阵C = A*B 矩阵M=CN∗N 将矩阵M中的全部元素取模6,得到 ...
- HDU 4965 Fast Matrix Calculation 矩阵快速幂
题意: 给出一个\(n \times k\)的矩阵\(A\)和一个\(k \times n\)的矩阵\(B\),其中\(4 \leq N \leq 1000, \, 2 \leq K \leq 6\) ...
- HDU 4965 Fast Matrix Calculation(矩阵高速幂)
HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个 ...
- HDU4965 Fast Matrix Calculation —— 矩阵乘法、快速幂
题目链接:https://vjudge.net/problem/HDU-4965 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Othe ...
- hdu 4965 Fast Matrix Calculation
题目链接:hdu 4965,题目大意:给你一个 n*k 的矩阵 A 和一个 k*n 的矩阵 B,定义矩阵 C= A*B,然后矩阵 M= C^(n*n),矩阵中一切元素皆 mod 6,最后求出 M 中所 ...
- 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 ...
- 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 ...
- Fast Matrix Calculation 矩阵快速幂
One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learni ...
- hdu4965 Fast Matrix Calculation (矩阵快速幂 结合律
http://acm.hdu.edu.cn/showproblem.php?pid=4965 2014 Multi-University Training Contest 9 1006 Fast Ma ...
随机推荐
- P1494 [国家集训队]小Z的袜子(luogu)
P1494 小Z的袜子 终于了解了莫队算法(更专业的名称Square Root Decomposition of Queries) 莫队算法: 一般来说解决静态(实际上也有修改的但复杂度更高)的离线( ...
- qt 透明化方法汇总
一. QT 透明设置 背景,标题栏透明,下级Widget,painter绘出来的(比如,drawtext,drawline)不透明 QWidget window; window.setWindowFl ...
- 利用CORS解决前后端分离的跨域资源问题
CORS 即CrossOrigin Resources Sharing-跨域资源共享,它定义了一种浏览器和服务器交互的方式来确定是否允许跨域请求.它是一个妥协,有更大的灵活性,但比起简单地允许所有这些 ...
- 【【henuacm2016级暑期训练】动态规划专题 O】Robot Rapping Results Report
[链接] 我是链接,点我呀:) [题意] 让你确定一个最小的k 使得1..k这些比赛的结果能够推导出所有人之间的实力大小 [题解] 如果关系越多.那么就越能确定所有人之间的大小关系. (多一点也能唯一 ...
- ArcEngine 一些实现代码
转自原文 ArcEngine 一些实现代码 ●·● 目录: A1 …………实现:鼠标滑过显示要素 tip A2 …………实现:通过鼠标选择要素并高亮显示(ISelectionEnvironme ...
- 鸟哥的Linux私房菜-----11、压缩指令与正则表示法
- ZOJ 2836
求不比M大的可以被集合任一个数整除的数的个数.(容斥原理) #include <iostream> #include <cstdio> #include <algorit ...
- codeforces7D Palindrome Degree(manacher&dp或Hsh&dp)
D. Palindrome Degree time limit per test 1 second memory limit per test 256 megabytes input standard ...
- ACdream 1127(Base Station-树状数组-2个约束条件)
Base Station Time Limit: 20000/10000MS (Java/Others)Memory Limit: 512000/256000KB (Java/Others) Subm ...
- linux内核模块笔记
主题: 1. 嵌入式基础知识 2. linux内核介绍 3. 内核的编译和安装(x86) 4. 第一个模块 5. 模块的相关工具 6. 模块的符号导出 7. 模块的參数 1.看linux/module ...