One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learning something about matrix, so he decided to make a crazy problem for her. Bob has a six-faced dice which has numbers 0, 1, 2, 3, 4 and 5 on each face.…
题意: 给出一个\(n \times k\)的矩阵\(A\)和一个\(k \times n\)的矩阵\(B\),其中\(4 \leq N \leq 1000, \, 2 \leq K \leq 6\). 矩阵\(C=A \cdot B\),求矩阵\(C^{N^2}\)的各个元素之和,以上矩阵运算均是在模\(6\)的情况下计算的. 分析: 如果我们直接计算\(A \cdot B\)的话,这个矩阵非常大,不可能进行快速幂计算. 所以要变形一下, \((A \cdot B)^{N^2}=A \cdot…
One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learning something about matrix, so he decided to make a crazy problem for her. Bob has a six-faced dice which has numbers 0, 1, 2, 3, 4 and 5 on each face.…
题目链接:https://vjudge.net/problem/HDU-4965 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2057    Accepted Submission(s): 954 Problem Description One day, Alice and Bob…
题目链接.hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N. 矩阵C = A*B 矩阵M=CN∗N 将矩阵M中的全部元素取模6,得到新矩阵M' 计算矩阵M'中全部元素的和 解题思路:由于矩阵C为N*N的矩阵,N最大为1000.就算用高速幂也超时,可是由于C = A*B, 所以CN∗N=ABAB-AB=AC′N∗N−1B,C' = B*A, 为K*K的矩阵,K最大为6.全然能够接受. #include <cstdio> #inc…
http://acm.hdu.edu.cn/showproblem.php?pid=4965 2014 Multi-University Training Contest 9 1006 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 238    Accepted Submission(…
Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 233…
题目 给定矩阵A, B和模数p,求最小的正整数x满足 A^x = B(mod p). 分析 与整数的离散对数类似,只不过普通乘法换乘了矩阵乘法. 由于矩阵的求逆麻烦,使用 $A^{km-t} = B(mod \ p)$ 形式的BSGS. 然后就是判断矩阵是否相等, 一种方法是对矩阵进行Hash, 这里为了防止两个不同矩阵的Hash值冲突,使用了两个底数进行Hash. #include<bits/stdc++.h> using namespace std; typedef long long l…
一种奇葩的写法,纪念一下当时的RE. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <string> #include <queue> #include <stack> #include <vec…
一开始看这个题目以为是个裸的矩阵快速幂的题目, 后来发现会超时,超就超在  M = C^(N*N). 这个操作,而C本身是个N*N的矩阵,N最大为1000. 但是这里有个巧妙的地方就是 C的来源其实 是= A*B, A为一个N*k的矩阵,B为一个k*N的矩阵,k最大为10,突破的就在这里,矩阵的结合律要用起来 即我先不把A*B结合,我先把B*A结合,这样M不是要C^N*N吗,就先把里面N*N个(B*A)算出来,就10*10再乘以logN*N即可.最后再两端乘一下A和B即可 也挺机智的,我没想到结…