标签:
30%的数据,满足 2 <= N <= 5 ; 1 <= T <= 30 。
100%的数据,满足 2 <= N <= 10 ; 1 <= T <= 1000000000 。
题解:我这辈子做的第一道真正意义上的矩阵乘法么么哒(phile:这。。。 HansBug:讨厌啦,都说了不要鄙视本宫TT)。。。据说矩阵乘法超级神奇,于是按照XXXXXXX来了一发。。。接下来还得继续学习,么么么哒~~~~
1 const p=2009; 2 type 3 sq=array[0..105,0..105] of longint; 4 var 5 i,j,k,l,m,n:longint; 6 a,b:sq; 7 cx:char; 8 function cc(a,b:sq):sq; 9 var 10 c:sq; 11 begin 12 fillchar(c,sizeof(c),0); 13 for k:=1 to n*9 do 14 for i:=1 to n*9 do 15 for j:=1 to n*9 do 16 c[i,j]:=(c[i,j]+(a[i,k]*b[k,j]) mod p) mod p; 17 cc:=c; 18 end; 19 procedure digit(var a:sq); 20 begin 21 fillchar(a,sizeof(a),0); 22 for i:=1 to n*9 do a[i,i]:=1; 23 end; 24 function ksm(a:sq;x:longint):sq; 25 var 26 c1,c2:sq; 27 begin 28 digit(c1);c2:=a; 29 while x>0 do 30 begin 31 if odd(x) then c1:=cc(c1,c2); 32 c2:=cc(c2,c2); 33 x:=x div 2; 34 end; 35 ksm:=c1; 36 end; 37 begin 38 readln(n,m); 39 for i:=1 to n do 40 for j:=2 to 9 do 41 a[i*9-9+j,i*9-9+j-1]:=1; 42 for i:=1 to n do 43 begin 44 for j:=1 to n do 45 begin 46 read(cx); 47 if cx<>‘0‘ then 48 a[j*9-8,i*9-9+ord(cx)-48]:=1; 49 end; 50 readln; 51 end; 52 b:=ksm(a,m); 53 writeln(b[n*9-8,1]); 54 end.
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4179262.html