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 |
。。。算是我的思考吧首先构造的矩阵1 A 0 A 所以平方之后就是1 A+A*A 0 A*A 再推一下发现这个矩阵k次方后右上角的就是答案 令a=右上角,b=右下角,由于左半边一直为1 0 所以每次平方运算结果(方式)为 a=a+a*b b=b*b 设结果矩阵为1 c 0 d 至于二进制下的k的某一位如果是1,则类似的:c=c+a*d d=b*d 如果是0,则不需与结果矩阵相乘 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 表达不清,下面代码 var a,b,c,d,e:array[0..40,0..40] of int64; n,m,k,i,j,kk:longint; begin readln(n,m,kk); for i:=1 to n do for j:=1 to n do begin read(a[i,j]); b[i,j]:=a[i,j]; end; fillchar(c,sizeof(c),0); fillchar(d,sizeof(d),0); for i:=1 to n do d[i,i]:=1; while m>0 do begin if m and 1=1 then begin fillchar(e,sizeof(e),0); for i:=1 to n do for j:=1 to n do for k:=1 to n do inc(e[i,j],a[i,k]*d[k,j] mod kk); for i:=1 to n do for j:=1 to n do c[i,j]:=(c[i,j]+e[i,j]) mod kk; fillchar(e,sizeof(e),0); for i:=1 to n do for j:=1 to n do for k:=1 to n do inc(e[i,j],b[i,k]*d[k,j] mod kk); for i:=1 to n do for j:=1 to n do d[i,j]:=e[i,j]; end; fillchar(e,sizeof(e),0); for i:=1 to n do for j:=1 to n do for k:=1 to n do inc(e[i,j],a[i,k]*b[k,j] mod kk); for i:=1 to n do for j:=1 to n do a[i,j]:=(a[i,j]+e[i,j]) mod kk; fillchar(e,sizeof(e),0); for i:=1 to n do for j:=1 to n do for k:=1 to n do inc(e[i,j],b[i,k]*b[k,j] mod kk); for i:=1 to n do for j:=1 to n do b[i,j]:=e[i,j]; m:=m shr 1; end; for i:=1 to n do begin write(c[i,1]); for j:=2 to n do write(' ',c[i,j]); writeln; end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator