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 |
不知道为什么大家写的代码都那么长?提供下我写的·。#include<stdio.h> #include<string.h> int b[65][65],x[65][65]; int n,k,m; void mul(int a[65][65],int x[65][65]) { int i,j,k; int t[65][65]; memset(t,0,sizeof(t)); for(i=0;i<n;i++) for(j=0;j<n;j++) for(k=0;k<n;k++) t[i][j]=(t[i][j]+a[i][k]*x[k][j])%m; memcpy(a,t,sizeof(t)); } int main() { int i,j; scanf("%d%d%d",&n,&k,&m); for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&x[i][j]); for(i=0;i<n;i++) { x[i+n][i]=1; x[i+n][i+n]=1; b[i][i]=1; b[i][i+n]=1; } n<<=1; for(i=0;(1<<i)<=k;i++) { if(k&(1<<i))mul(b,x); mul(x,x); } n>>=1; for(i=0;i<n;i++)b[i][i]=(b[i][i]-1+m)%m; for(i=0;i<n;i++) { for(j=0;j<n-1;j++)printf("%d ",b[i][j]); printf("%d\n",b[i][n-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