题目链接:FZU 1692
题意:每次按a[i]=(a[i]+L*a[(i+1)%n]+R*a[(i-1+n)%n])%M(原题打错了),操作m次后n个数的结果
分析:
矩阵挺好想的:
1 L 0 0 0 0 R a[0]
R 1 L 0 0 0 0 a[1]
0 R 1 L 0 0 0 a[2]
. . . . . . . a[n-1](依次类推)
就是如果直接套快速幂板子会超时.
我们很容易(我没发现 o(≧口≦)o)发现这是个循环矩阵.有矩阵C=AB,如果A和B是循环矩阵则C也是循环矩阵.
- 循环矩阵: 行向量的每个元素都是前一个行向量各元素依次右移一个位置得到的结果。
以下是代码:
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Fi firs