Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大佬们能告诉我为什么会RE吗#include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> using namespace std; #define N 200 int n, k, mod, s[N][N]; struct mat{int a[N][N];}a; mat mul(mat a, mat b){ mat ans; for(int i=0;i<n*2;i++) for(int j=0;j<n*2;j++){ ans.a[i][j]=0; for(int k=0;k<n*2;k++){ ans.a[i][j]+=a.a[i][k]*b.a[k][j]; ans.a[i][j]%=mod; } } return ans; } mat qpow(mat a, int n){ mat ans; memset(ans.a,0,sizeof(ans.a)); for(int i=0;i<n*2;i++) ans.a[i][i]=1; while(n){ if(n&1) ans=mul(ans, a); a=mul(a,a); n>>=1; } return ans; } int main(){ cin>>n>>k>>mod; for(int i=0;i<n;i++) for(int j=0;j<n;j++){ cin>>s[i][j]; s[i][j]%=mod; } for(int i=0;i<2*n;i++)for(int j=0;j<2*n;j++) a.a[i][j]=0; for(int i=0;i<n;i++) a.a[i][i]=1; for(int i=0;i<n;i++) for(int j=0;j<n;j++) a.a[i+n][j+n]=s[i][j]; for(int i=0;i<n;i++) for(int j=0;j<n;j++) a.a[i][j+n]=s[i][j]; mat ans; ans=qpow(a,k); for(int i=0;i<n;i++){ for(int j=n;j<n*2-1;j++) printf("%d ", ans.a[i][j]); printf("%d\n", ans.a[i][n*2-1]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator