HDU 1575 Tr A【矩阵幂】
来源:互联网 发布:alphago知乎 编辑:程序博客网 时间:2024/05/23 20:22
题目点这
求对角线和 [ (A^k)%9973 ]
矩阵幂即可,轻松
#include <cstdio>#include <cmath>#include <cstring>#include <set>#include <stack>#include <queue>#include <vector>#include <iostream>using namespace std;#include <algorithm>#define ll long long#define INF 0x7FFFFFFF#define INT_MIN -(1<<31)#define eps 10^(-6)#define Q_CIN ios::sync_with_stdio(false)#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define REV( i , n ) for ( int i = n - 1 ; i >= 0 ; -- i )#define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define FOV( i , a , b ) for ( int i = a ; i >= b ; -- i )#define CLR( a , x ) memset ( a , x , sizeof (a) )#define RE freopen("1.in","r",stdin)#define WE freopen("1.out","w",stdout)#define MOD 10009#define NMAX 10002#define min(a,b) ((a)>(b)?(b):(a))int n,k;struct Matrix{ int v[15][15];}m0;Matrix mul(Matrix A,Matrix B){ Matrix C; REP(i,n) { REP(j,n) { C.v[i][j] = 0; REP(k,n) { C.v[i][j] += A.v[i][k] * B.v[k][j]; } C.v[i][j] %= 9973; } } return C;}Matrix mtPow(Matrix A, int k){ if(k == 1) return A; A = mtPow(A, k / 2); if(k % 2 == 0) return mul(A, A); else return mul(mul(A, A), m0);}int main(){ int t; //RE; cin>>t; while(t--) { cin>>n>>k; REP(i,n) REP(j,n) cin>>m0.v[i][j]; Matrix m1 = mtPow(m0, k); /* REP(i,n){ REP(j,n) cout<<m1.v[i][j]<<" "; cout<<endl;}*/ int ans = 0; REP(i,n) ans += m1.v[i][i]; cout<<ans%9973<<endl; }return 0;}
0 0
- hdu 1575Tr A 矩阵快速幂
- HDU 1575 Tr A(矩阵快速幂)
- HDU 1575 Tr A 矩阵的幂
- HDU 1575 Tr A【矩阵幂】
- HDU 1575 Tr A (矩阵快速幂)
- HDU 1575-Tr A(矩阵快速幂)
- HDU 1575 Tr A (矩阵快速幂)
- HDU - 1575 Tr A(矩阵快速幂)
- hdu 1575 Tr A(矩阵快速幂)
- Hdu 1575 Tr A【矩阵快速幂】
- HDU 1575 Tr A (矩阵快速幂)
- 【HDU 1575】Tr A (矩阵快速幂)
- HDU 1575 Tr A 矩阵快速幂
- 【HDU 1575 Tr A】+ 矩阵快速幂
- HDU-1575-Tr A【矩阵快速幂】
- hdu 1575 TR A 矩阵快速幂
- HDU 1575 - Tr A(矩阵快速幂)
- HDU 1575 Tr A 矩阵快速幂
- 漂亮打印问题与动规模型的建立
- U-Boot的常用命令详解
- Tomcat中实现IP访问限制
- 数据刷新究竟应该发生在哪?ViewController内部,还是开放Api让外部调用
- javascript增加一行
- HDU 1575 Tr A【矩阵幂】
- DDR SDRAM布线规则
- Juce源码分析(八)强引用与弱引用
- 根据IP(有代理的情况)定位城市以及通过nginx转发的tomcat如何得到用户真实的ip
- 黄金数据查询演示示例
- 干货分享!2014中国互联网大会PPT下载合集
- 去耦电容的容值计算和布局布线
- linux的du和df命令
- Qt程序打包发布的问题