51nod 1113 矩阵快速幂
来源:互联网 发布:知乎永久禁言怎么解除 编辑:程序博客网 时间:2024/06/09 17:09
最简单的四级题,上模板。
#include <iostream>#include <vector>using namespace std;typedef long long ll;typedef vector<ll> vec;typedef vector<vec> mat;const ll mod = 1e9+7;mat mul(mat& A, mat &B){ mat C(A.size(),vec(B[0].size())); for(int i = 0; i < A.size(); ++i) for(int k = 0; k < B.size(); ++k) for(int j = 0; j < B[0].size(); ++j) C[i][j] = (C[i][j]+A[i][k]*B[k][j])%mod; return C;}mat pow(mat A, ll n){ mat B(A.size(),vec(A.size())); for(int i = 0; i < A.size(); ++i) B[i][i] = 1; while(n > 0) { if(n&1) B = mul(B,A); A = mul(A,A); n >>= 1; } return B;}void solve(ll n, ll m){ mat A(n,vec(n)); for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) cin >> A[i][j]; } A = pow(A,m); for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) cout << A[i][j] << " "; cout << endl; }}int main(){ ios::sync_with_stdio(false); ll n,m; cin >> n >> m; solve(n,m); return 0;}
阅读全文
0 0
- 51nod 1113矩阵快速幂
- 51nod-1113 矩阵快速幂
- 51nod 1113 矩阵快速幂
- 51Nod 1113 矩阵快速幂
- 51nod 1113 矩阵快速幂
- 51nod--1113 矩阵快速幂
- 51nod 1113 矩阵快速幂
- 51nod 1113 矩阵快速幂
- 矩阵快速幂 51nod
- 51nod 1113 矩阵快速幂 (矩阵的n次方)
- 20140911 【 初等数论 】 51nod 1113 . 矩阵快速幂
- 51Nod-1113-矩阵快速幂
- 51nod 1113 矩阵快速幂【裸题】【内含黑科技】
- 51nod 1113 矩阵快速幂(模板题)
- 51nod 1126(矩阵快速幂)
- 51nod - 1573 分解 - 矩阵快速幂
- 51nod 1537 分解 (矩阵快速幂)
- 51nod 矩阵快速幂模版题
- Matlab求解数学问题
- MVC观察者框架
- Web Service笔记(一):WS简介与CXF初步
- HTML表格
- git commit -m和git commit -am
- 51nod 1113 矩阵快速幂
- 在这里将开始我的新博客生活
- 正则表达式test()检测不到字符串
- Unity 音效管理
- CentOS 安装pip
- Java正则表达式非贪婪提取字符串中的每个数字
- 阿里云部署并启动tomcat遇到的坑
- 【转】正则匹配函数——regcomp和regexec
- 刷题六