• bzoj1898


    这是yhc大牛矩乘论文上的题目,那里面分析得很清楚了
    这里就说说我一开始错的地方,我一开始处理每个时刻能通过的邻接矩阵的时候
    把以不能访问的点i为起点和终点的都标记为0了,实际上只能标记以i为终点的边即可
    很好理解,是自己太脑残了

      1 const mo=10000;
      2 var b,c,g,f:array[0..51,0..51] of longint;
      3     v:array[0..51,0..51] of boolean;
      4     w,d:array[0..51] of longint;
      5     a:array[0..15,0..51,0..51] of longint;
      6     fish,i,j,k,x,y,n,m,s,e,t:longint;
      7 
      8 procedure work(i:longint);
      9   var j,k:longint;
     10   begin
     11     a[i]:=f;
     12     for j:=1 to n do
     13       if v[j,i] then
     14       begin
     15         for k:=1 to n do
     16           a[i,k,j]:=0;
     17       end;
     18   end;
     19 
     20 procedure mul(p:longint);
     21   var i,j,k:longint;
     22   begin
     23     b:=c;
     24     for i:=1 to n do
     25       for j:=1 to n do
     26       begin
     27         c[i,j]:=0;
     28         for k:=1 to n do
     29           c[i,j]:=(c[i,j]+b[i,k]*a[p,k,j] mod mo) mod mo;
     30       end;
     31   end;
     32 
     33 procedure time;
     34   var i,j,k:longint;
     35   begin
     36     for i:=1 to n do
     37       for j:=1 to n do
     38       begin
     39         c[i,j]:=0;
     40         for k:=1 to n do
     41           c[i,j]:=(c[i,j]+g[i,k]*f[k,j] mod mo) mod mo;
     42       end;
     43   end;
     44 
     45 procedure quick(x:longint);
     46   var i,j:longint;
     47   begin
     48     j:=0;
     49     while x>0 do
     50     begin
     51       inc(j);
     52       d[j]:=x mod 2;
     53       x:=x shr 1;
     54     end;
     55     fillchar(c,sizeof(c),0);
     56     for i:=1 to n do
     57       c[i,i]:=1;
     58     for i:=j downto 1 do
     59     begin
     60       g:=c;
     61       f:=c;
     62       time;
     63       if d[i]=1 then
     64       begin
     65         g:=c;
     66         f:=b;
     67         time;
     68       end;
     69     end;
     70   end;
     71 
     72 begin
     73   readln(n,m,s,e,t);
     74   inc(s);
     75   inc(e);
     76   for i:=1 to m do
     77   begin
     78     readln(x,y);
     79     inc(x);
     80     inc(y);
     81     f[x,y]:=1;
     82     f[y,x]:=1;
     83   end;
     84   readln(fish);
     85   for i:=1 to fish do
     86   begin
     87     read(y);
     88     for j:=0 to y-1 do
     89     begin
     90       read(x);
     91       inc(x);
     92       k:=j;
     93       while k<=12 do
     94       begin
     95         v[x,k]:=true;
     96         k:=k+y;
     97       end;
     98     end;
     99   end;
    100   for i:=0 to 12 do
    101     work(i);
    102   if t<12 then
    103   begin
    104     c:=a[1];
    105     for i:=2 to t do
    106       mul(i);
    107   end
    108   else begin
    109     c:=a[1];
    110     for i:=2 to 12 do
    111       mul(i);
    112     b:=c;
    113     quick(t div 12);
    114     for i:=1 to t mod 12 do
    115       mul(i);
    116   end;
    117   writeln(c[s,e]);
    118 end.
    View Code
  • 相关阅读:
    【JMeter】if语句中不能Failure=false解决办法
    【java】method.invoke(方法底层所属对象/null,new Object[]{实际参数})
    【java设计模式】【行为模式Behavioral Pattern】模板方法模式Template Method Pattern
    【java设计模式】代理模式
    33-算法训练 安慰奶牛
    32-java 里面list的问题
    31-java中知识总结:list, set, map, stack, queue
    30-算法训练 最短路 spfa
    29-算法训练 结点选择-超时了!!!
    28-算法训练 最大最小公倍数 -贪心
  • 原文地址:https://www.cnblogs.com/phile/p/4473056.html
Copyright © 2020-2023  润新知