【BZOJ4128】Matrix BSGS+hash】的更多相关文章

[BZOJ4128]Matrix Description 给定矩阵A,B和模数p,求最小的x满足 A^x = B (mod p) Input 第一行两个整数n和p,表示矩阵的阶和模数,接下来一个n * n的矩阵A.接下来一个n * n的矩阵B Output 输出一个正整数,表示最小的可能的x,数据保证在p内有解 Sample Input 2 7 1 1 1 0 5 3 3 2 Sample Output 4 HINT 对于100%的数据,n <= 70,p <=19997,p为质数,0<…
题目描述 给定矩阵A,B和模数p,求最小的x满足 A^x = B (mod p) 输入 第一行两个整数n和p,表示矩阵的阶和模数,接下来一个n * n的矩阵A.接下来一个n * n的矩阵B 输出 输出一个正整数,表示最小的可能的x,数据保证在p内有解 样例输入 2 7 1 1 1 0 5 3 3 2 样例输出 4 题解 矩阵乘法+Hash+BSGS 看到题目很容易想到BSGS算法,但要求逆元,而矩阵的逆不是很好求出,怎么办? 事实上,BSGS有两种形式:$a^{km+t}\equiv(mod\…
Description Given an N × M matrix, your task is to find the number of occurences of an X × Y pattern. InputThe first line contains a single integer t (t ≤ 15), the number of test cases.For each case, the first line contains two integers N and M (N, M…
[论文标题]Matrix Factorization Techniques for Recommender Systems(2009,Published by the IEEE Computer Society) [论文作者]Yehuda Koren(Yahoo Research) , Robert Bell and Chris Volinsky( AT&T Labs—Research) [论文链接]Paper(8-pages // Double column) [Info] 此篇论文的作者是n…
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N). We can change the matrix in the following way. Given a rectangle whose upp…
[BZOJ1125][POI2008]Poc Description n列火车,每条有l节车厢.每节车厢有一种颜色(用小写字母表示).有m次车厢交换操作.求:对于每列火车,在交换车厢的某个时刻,与其颜色完全相同的火车最多有多少. Input n l m (2 ≤ n ≤ 1000, 1 ≤ l ≤ 100, 0 ≤ m ≤ 100000) n行字符串,长度为l m行,每行4个数a b c d,a车的第b个字符与c车第d个字符交换. Output n个数,在交换车厢的某个时刻,与该车颜色完全相同的…
[BZOJ2081][Poi2010]Beads Description Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串),每块有k(k>0)个珠子,如果这条珠子的长度不是k的倍数,最后一块小于k的就不要拉(nc真浪费),保证珠子的长度为正整数. Zxl喜欢多样的项链,为她应该怎样选择数字k来尽可能得到更多的不同的子串感到好奇,子串都是可以反转的,换句话说,子串(1,2,3)和(3,2,1)是一样的.写一个程序,为Zxl…
上一篇博文中说道了baby step giant step的方法(简称BSGS),不过对于XY mod Z = K ,若x和z并不互质,则不能直接套用BSGS的方法了. 为什么?因为这时候不存在逆元了啊,那么怎么办呢? 既然是x和z不互质,那么我们就想办法让他们互质,再套用BSGS的解法即可.(这就是所谓的消因子法) 代码如下: #include<cstdio> #include<cstring> #include<cstring> #include<iostre…
题目链接 二维\(Hash\)类似二维前缀和,每一行看成一个\(h\)进制数,每一个以(1,1)为左上角的矩阵看成一个由每一行的\(Hash\)值组成的\(l\)进制数. 然后自己推推柿子就行. #include <cstdio> #include <cstring> #include <map> using namespace std; #define Open(s) freopen(s".in","r",stdin); fre…
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4128 大水题一道 使用大步小步算法,把数字的运算换成矩阵的运算就好了 矩阵求逆?这么基础的线代算法我也不想多说,还是自行百度吧 需要注意的是矩阵没有交换律,所以在计算$B\cdot A^{-m}$的时候不要把顺序搞混 代码: #include <cstring> #include <cstdio> #include <algorithm> #include <…