显然知道第一行就可以只道整个矩阵
但n<=40,搜索是不行的,我们设第一行为x1~xm
可以由轻易由第一行未知数推出第n+1行,这一步我们可以压成二进制位(因为只和奇偶有关)
显然n+1行必须是0,由此可以列方程高斯消元即可

 1 var a,c:array[0..50,0..50] of longint;
 2     b:array[0..50,0..50] of int64;
 3     n,m,i,j:longint;
 4 
 5 procedure swap(var a,b:longint);
 6   var c:longint;
 7   begin
 8     c:=a;
 9     a:=b;
10     b:=c;
11   end;
12 
13 procedure gauss;
14   var i,j,k,p:longint;
15   begin
16     k:=1;
17     for i:=1 to m do
18     begin
19       j:=k;
20       while (j<=m) and (a[j,i]=0) do inc(j);
21       if (j>m) then continue;
22       if j<>k then
23       begin
24         for p:=i to m+1 do
25          swap(a[k,p],a[j,p]);
26       end;
27       for j:=k+1 to m do
28         if a[j,i]=1 then
29         begin
30           for p:=i to m+1 do
31             a[j,p]:=a[j,p] xor a[k,p];
32         end;
33       inc(k);
34     end;
35     for i:=m downto 1 do
36     begin
37       c[1,i]:=a[i,m+1];
38       if a[i,i]=0 then
39       begin
40         c[1,i]:=1;
41         continue;
42       end;
43       for j:=i+1 to m do
44         if a[i,j]=1 then c[1,i]:=c[1,i] xor c[1,j];
45     end;
46   end;
47 
48 begin
49   readln(n,m);
50   for i:=1 to m do
51     b[1,i]:=int64(1) shl int64(i-1);
52 
53   for i:=2 to n+1 do
54     for j:=1 to m do
55       b[i,j]:=b[i-1,j] xor b[i-1,j+1] xor b[i-1,j-1] xor b[i-2,j];
56 
57   for i:=1 to m do
58     for j:=1 to m do
59       if b[n+1,i] and (int64(1) shl int64(j-1))<>0 then a[i,j]:=1;
60 
61   gauss;
62   for i:=2 to n do
63     for j:=1 to m do
64       c[i,j]:=c[i-1,j] xor c[i-1,j+1] xor c[i-1,j-1] xor c[i-2,j];
65 
66   for i:=1 to n do
67   begin
68     for j:=1 to m-1 do
69       write(c[i,j],' ');
70     writeln(c[i,m]);
71   end;
72 end.
View Code

 

posted on 2015-04-04 22:21  acphile  阅读(154)  评论(0编辑  收藏  举报