Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大佬们能告诉我为什么会RE吗

Posted by str_hj at 2018-09-16 22:37:20 on Problem 3233
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator