# 沼泽鳄鱼（矩阵乘法）

ZJTSC 沼泽鳄鱼

Description

Input

Output

Sample Input

6 8 1 5 3
0 2
2 1
1 0
0 5
5 1
1 4
4 3
3 5
1
3 0 5 1

Sample Output

2
【样例说明】
时刻    0       1       2       3
鱼位置  0       5       1       0
路线一  1       2       0       5
路线二  1       4       3       5



【约定】
1 ≤ N ≤ 50
1 ≤ K ≤ 2,000,000,000

1 ≤ NFish ≤ 20

A[i]代表第i个时刻的邻接矩阵,Ans[start,end]为所求。那么Ans=A[1]*A[2]*A[3]*…..*A[K]

A[1]*A[2]*……*A[12]=A[12p+1]*A[12p+2]*……*A[12p+12] (p为任意正整数)

Ans=(A[1]*A[2]*……*A[12])k div 12 *(A[1]*A[2]*……*A[k mod 12])

·              const
·                p=10000;
·
·              type
·                arr=array[1..50,1..50] of longint;
·
·              var
·                n,m,s,e,t,w1,nf,x,y,i,j,k,u:longint;
·                a,c,d:arr;
·                f:array[1..12] of arr;
·                w:array[1..4] of longint;
·
·              procedure cheng(a,b:arr);
·              var
·                i,j,k:longint;
·              begin
·                fillchar(c,sizeof(c),0);
·                for i:=1 to n do
·                  for j:=1 to n do
·                    for k:=1 to n do
·                      c[i,j]:=(c[i,j]+a[i,k]*b[k,j]) mod p;
·              end;
·
·              procedure ksm(x:longint);
·              begin
·                if x=0 then exit;
·                ksm(x div 2);
·                cheng(c,c);
·                if x mod 2=1 then cheng(c,d);
·              end;
·
·              begin
·                readln(n,m,s,e,t);
·                for i:=1 to m do
·                begin
·                  readln(x,y);
·                  a[x+1,y+1]:=1; (因为石柱是0~n-1，加1更好算)
·                  a[y+1,x+1]:=1;
·                end;
·                readln(nf);
·                for i:=1 to 12 do
·                  f[i]:=a;
·                for i:=1 to nf do
·                begin
·                  read(w1);
·                  for j:=1 to w1 do
·                    read(w[j]);
·                  for j:=1 to 12 do
·                  begin
·                    u:=j mod w1+1;
·                    for k:=1 to n do
·                      f[j,k,w[u]+1]:=0;
·                  end;
·                end;
·                for i:=1 to n do
·                  c[i,i]:=1;
·                for i:=1 to 12 do
·                  cheng(c,f[i]);
·                d:=c;
·                fillchar(c,sizeof(c),0);
·                for i:=1 to n do
·                  c[i,i]:=1;
·                ksm(t div 12);
·                for i:=1 to t mod 12 do
·                  cheng(c,f[i]);
·                writeln(c[s+1,e+1]);
·              end.
·

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120