一种奇葩的写法,纪念一下当时的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. 04 SqlServer

    数据库的注释 –(两个横线) 主键表 外键表 主键,组合主键 SqlServer 使用附加 权限 主文件mdf 日志文件ldf 数据类型 char varchar nchar nvarchar cha ...

  2. 小程序(Wepy)--生成海报图片

    对于小程序的分享, 除了分享给朋友, 好友群,是可以直接做到的, 但是要想扩大推广范围, 通过生成海报图片, 将自己小程序码带进去,应该是目前我所知的好办法了. 但是海报也不是那么好搞.之前自己手写出 ...

  3. [USACO15DEC]最大流Max Flow

    树剖LCA+树上差分. 树上差分的基本操作. #include <queue> #include <iostream> #include <cstdio> usin ...

  4. 用pycharm运行django项目

    [点击]run -> Edit Configrations 弹出如下页面 点击“+” 点击Django server 在弹出页面的host填0.0.0.0 点击这个“文件夹” 点击‘+’后填下面 ...

  5. [luogu] P4040 [AHOI2014/JSOI2014]宅男计划(贪心)

    P4040 [AHOI2014/JSOI2014]宅男计划 题目背景 自从迷上了拼图,JYY就变成了个彻底的宅男.为了解决温饱问题,JYY不得不依靠叫外卖来维持生计. 题目描述 外卖店一共有N种食物, ...

  6. [luogu] P4105 [HEOI2014]南园满地堆轻絮 (贪心)

    P4105 [HEOI2014]南园满地堆轻絮 题目描述 小 Z 是 ZRP(Zombies' Republic of Poetry,僵尸诗歌共和国)的一名诗歌爱好者,最近 他研究起了诗词音律的问题. ...

  7. C#-逆变 协变 反射 代码

    首先看一段测试代码,自己写的 class Program { static void Main(string[] args) { man OneMan = new man(); var d = One ...

  8. Qt之二维码扫描

    简述 二维码(QR Code)是用某种特定的几何图形按一定规律在平面(二维方向)分布的黑白相间的图形记录数据符号信息的.是所有信息数据的一把钥匙.应用十分广泛,如:产品防伪/溯源.广告推送.网站链接. ...

  9. debian mysql 定时自己主动备份的脚本

    #!/bin/sh LOG=/var/log/mysql-backup.log # mysql db info USER_ROOT=XXXXXX USER_PWD=XXXXXXX # mysql da ...

  10. leveldb学习:sstable(2)

    block写入:block_builder block.h和.cc里定义了block的entry存储格式和restart,提供了entry的查找接口以及迭代器.那么怎样往写block里写entry呢? ...