• vijos1049送给圣诞夜的礼品


    这题犯了两个sb错误,写下来,为以后做个警告

    一、mul过程中将k作为了循环变量

    二、看错了题……

          题目中说是数到k行,而我却以为数k遍……

    做矩阵乘法,只要记住一句话:置换一定可以写成矩阵的形式!

    并且:矩阵满足结合律,不满足交换率!

    代码:

     1 type matrix=array[0..110,0..110] of longint;
     2 var a:array[0..15] of matrix;
     3     b,c:matrix;
     4     i,j,n,m,k,x:longint;
     5     ans,d:array[0..150] of longint;
     6 procedure tiao(x:matrix);
     7  var i,j:longint;
     8  begin
     9  for i:=1 to n do
    10   begin
    11    for j:=1 to n do write(x[i,j]);
    12    writeln;
    13   end;
    14  end;
    15 procedure init;
    16  begin
    17    readln(n,m,k);
    18    fillchar(a,sizeof(a),0);
    19    fillchar(b,sizeof(b),0);
    20    fillchar(c,sizeof(c),0);
    21    for i:=1 to m do
    22     begin
    23       for j:=1 to n do
    24         begin
    25           read(x);
    26           a[i,x,j]:=1;
    27         end;
    28       readln;
    29     end;
    30    for i:=1 to n do begin b[i,i]:=1;c[i,i]:=1;end;
    31  end;
    32 procedure mul(var x,y,z:matrix);
    33  var t:matrix;
    34      i,j,l:longint;
    35  begin
    36    fillchar(t,sizeof(t),0);
    37    for i:=1 to n do
    38      for j:=1 to n do
    39        for l:=1 to n do
    40          inc(t[i,j],x[i,l]*y[l,j]);
    41    z:=t;
    42  end;
    43 procedure ksm(cs:longint);
    44  begin
    45    while cs<>0 do
    46     begin
    47       if cs and 1=1 then mul(b,c,c);
    48       cs:=cs>>1;
    49       mul(b,b,b);
    50     end;
    51  end;
    52 procedure main;
    53  begin
    54    for i:=1 to m do mul(b,a[i],b);
    55    ksm(k div m);
    56    for i:=1 to k mod m do mul(c,a[i],c);
    57    for i:=1 to n do d[i]:=i;
    58    fillchar(ans,sizeof(ans),0);
    59    for i:=1 to n do
    60      for j:=1 to n do
    61       inc(ans[i],d[j]*c[j,i]);
    62    for i:=1 to n do write(ans[i],' ');
    63  end;
    64 begin
    65   init;
    66   main;
    67 end.       
    View Code
  • 相关阅读:
    spring boot自动配置
    servlet类与Spring Controller类的关系
    Junit中的setup和teardown方法
    dependency的scope
    mapper的namespace
    mybatis缓存
    Ehcache(05)——缓存的查询
    Ehcache(04)——设置缓存的大小
    Ehcache(03)——Ehcache中储存缓存的方式
    Ehcache(02)——ehcache.xml简介
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3802765.html
Copyright © 2020-2023  润新知