Some Thoughts Latin square

problem:

Latin square (English: Latin square) is a \ (n × n \) of the square, in which the n-× the n-$ \ (the square where exactly \) the n-$ different elements, each different kinds of elements appear only once in the same row or column.

\[ \begin{bmatrix} 1&2&3 \\\ 2&3&1 \\\ 3&1&2 \end{bmatrix} \begin{bmatrix}a&b&d&c \\\ b&c&a&d \\\ c&d&b&a \\\ d&a&c&b \end{bmatrix} \]

Currently, there is no formula to calculate the (n × n \) \ number of Latin square.

Standard

When a first row of the Latin square matrix of elements arranged in order of the first column, this is the standard Latin square.

The figure is a standard type:

\(\left[ \begin{array}{cccc} 1 & 2 & 3 & 4 \\\ 2 & 1 & 4 & 3 \\\ 3 & 4 & 1 & 2 \\\ 4 & 3 & 2 & 1 \end{array} \right]\)

The same type of category

Many produce new Latin square Latin square for the operation will be. For example, he said Latin square in the exchange line, in exchange Latin square column, or exchange symbol Latin square in the elements, will get a new Latin square. Latin Square sign resulting in the exchange line, the exchange column in the Latin Square, Latin square or switching elements in a new and original Latin square Latin Square called isotype (isotopic). Isotype (isotopism) is an equivalence relation, so all of the Latin square formed by the set may be divided into isotype classes (isotopic class) of the subset, the same type of Latin square belong to the same isotype category, not belonging to the same isotype category Latin square is different type.

The same type of calculation

Taken intellectuals love to ask

first step

One of the simplest first set discharge method, it is assumed in the first row 1, column 1

The first row, \ (n-. 1 ~, \)
of the second row, \ (~ n-2,. 1, \)
the third row, \ (n-~. 3, 1,2, \)
fourth row, \ (4 ~ n, 1,2,3, \)
of \ (n-1 \) row, \ (. 1-n-, n-,. 1 ~ (2-n-), \)
of \ (n-\) rows, \ (n-, 1 ~ (n-1), \)

The second step

The second \ (2 \) to the second \ (n-\) rows (the whole row) at any position transducer rearranged to meet the requirements of the total, a total of \ ((n-1)! \) Species discharge method,

third step

The second \ (2 \) to the second \ (n-\) column (aligned) at any position transducer rearranged to meet the requirements of the total, a total of \ ((n-1)! \) Species discharge method,

the fourth step

The first \ (1 \) row \ (1 \) respectively, may be switched to the second \ (2 ~ n \) column, before the first count \ (1 \) column, a total of \ (n-\) species discharge method,
so A total of \ (n \ times (n- 1)! \ times (n-1)! = n! \ times (n-1)! \) seed discharge method.

end

That is a known for a Latin square, of the same type are \ (n! \ Times (n -1)! \) Th

The so-called "known solution ranks of exchange" repeat reasons

Taken know almost

Suppose you first meet casually come up with a set of circumstances, then you can just sort lines disrupted, \ (4! = 24 \) , empathy column also, \ (4! = 24 \)
two cases together , \ (24 * 24 = 576 \) .

The above might say the solution is "known solution ranks of the exchange."
(1) \ (n \ times n \) form, is the result of exchange ranks \ (S = n-! \ N-Times! \) . For \ (2 \ times 2 \) and \ (3 \ times 3 \) at the table \ (s \) are \ (4,36 \) , but in fact only \ (2,12 \) possible. So first guess would duplicate the ranks of exchange.
(2) In order to verify whether the ranks of exchange duplication solution, I use the program \ (4 \ times 4 \) form the ranks were exchanged, after the de-emphasis is \ (144 \) species do exist repeated.
(3) then the correct result is \ (144 \) do? Then be exhaustive, list all screening solution, the de-emphasis is \ (576 \) species seen for the known solution ranks exchange, all solutions can not cover.

The above points demonstrate the ranks of exchange of ideas is wrong (although it \ (4 \ times 4 \) got the time to correct results).

Speak from:

You can give the ranks of the label:

If the first row \ (the n-1,2,3,4 ...... \) .
After the column exchange a second row can be made consistent with the first row, and each of the remaining new consistent with previous row a row, then the row exchange can be obtained consistent with the original matrix. There \ (n \) line, there \ (n \) kind of duplication.

So the same to obtain: For a given Latin square, of the same type are \ (\ frac {n} = n \ times (n-1) \ {(n ^ 2)!}!!) Th

Take \ (4 \ times 4 \) to make an example

For example, a Latin square is known:

\(\begin{array} & & & 1 & 2 & 3 & 4 \end{array}\\\ \begin{array}{} 1 \\ 2 \\ 3 \\ 4 \end{array} \begin{bmatrix}{} 1 & 2 & 3 & 4 \\\ 2 & 3 & 4 & 1 \\\ 3 & 4 & 1 & 2 \\\ 4 & 1 & 2 & 3 \end{bmatrix}\)

First performed 列交换after:

$ \begin{array} & & & 4 & 1 & 2 & 3 \end{array}\ \begin{array}{} 1 \ 2 \ 3 \ 4 \end{array} \begin{bmatrix}{} 4 & 1 & 2 & 3 \ 1 & 2 & 3 & 4 \ 2 & 3 & 4 & 1 \ 3 & 4 & 1 & 2 \end{bmatrix}$

Then 行交换after:

$ \begin{array} & & & 4 & 1 & 2 & 3 \end{array}\ \begin{array}{} 2 \ 3 \ 4 \ 1 \end{array} \begin{bmatrix}{} 1 & 2 & 3 & 4 \ 2 & 3 & 4 & 1 \ 3 & 4 & 1 & 2 \ 4 & 1 & 2 & 3 \end{bmatrix}$

行列标号的排列By the \ (1,2,3,4 / 1,2,3,4 \) becomes \ (2,3,4,1 / 4,1,2,3 \) , but Latin square 未变.

For a can of (I \) \ row becomes the first row of the column of labels 排列, be able to find 唯一一个arrangement enables Latin Square same row label.

As above 行列标号的排列, to obtain the same Latin square 排列with a \ (4 \) species.

\(1,2,3,4/1,2,3,4\)

\(2,3,4,1/4,1,2,3\)

\(3,4,1,2/3,4,1,2\)

\(4,1,2,3/2,3,4,1\)

Standard calculations

As if the world can only find violence up to \ (the n-11 = \) .

You can look OEIS (On-Line Encyclopedia of Integer Sequences) of A000315

First serve their own code to write:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<ctime> 
#define fr(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int MaxL=20,Max=1e5;
typedef long long ll;
int M[Max][MaxL];
int *m[MaxL];
int n,tot=0,numtot=0;
void dfs(int,int);
bool check(int);
void make();
int main()
{
//  fr(latin);
    int T[Max];
    scanf("%d",&n);
    for(int i=0;i<n;i++) T[i]=i+1;
    do
    {
        ++numtot;
        for(int j=0;j<n;j++) M[numtot][j]=T[j];
    }while(next_permutation(T,T+n)); 
    m[1]=&M[1][0];
    dfs(2,1);
    printf("%d\n",tot);
    fprintf(stderr,"%.3f s\n",clock()*1.0/CLOCKS_PER_SEC);
    return 0;
}
void dfs(int line,int num)
{
    if(line>n) return ++tot,make(),void();
    if(num>numtot) return;
    for(int i=num;i<=numtot;i++)
    {
        m[line]=&M[i][0];
        if(check(line)) dfs(line+1,i+1);
    }
//  while(!check(line)) m[line]=&M[++num][0];   
    return;
}
bool check(int line)
{
    for(int i=line-1;i;i--)
    {
        for(int j=0;j<n;j++) 
            if(!((*(m[line]+j))^(*(m[i]+j)))) return false;
    }
    return true;
}
void make()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<n;j++) printf("%d ",(*(m[i]+j)));
        puts("");
    }
    puts("");
}

All of the number of Latin square

Why say before 标准型?

Because for a \ (n-\) between order Latin square, a different standard is not 同型, in other words, as long as the known \ (n-\) Order the standard Latin Square number, multiplied by the number of the same type, All that is \ (n \) the number of order Latin square.

But the international community can only find violence up to \ (the n-11 = \) .

PS:

I wrote a program with violent look \ (n = 7 \) standard when the number of time:

10001.097 s

US \ (2h50min \) (scared ~ ~)

time.png

High school math

In the (4 × 4 \) \ squares in each grid are filled \ (1,2,3,4 \) one of four numbers, requires each row, column numbers are not repeated, different fill French total ()

A. \ (24 \) species B. \ (144 \) species C. \ (432 \) species D. \ (576 \) species

If you already know the Latin Square, and know \ (n = 4 \) when the standard number is \ (4 \) when Congratulations, this question spike ~

That if you do not know anything about it ......

There are more conventional methods.

begin

We can determine line by line.

The first line is no limit, a total of \ (4! = 24 \) species.

Suppose a set of extraction \ ([a, b, c , d] \) as the first row.

According to the conclusions of the problem the wrong row, the second row has \ (9 \) species.

That third row it?

We found that things are not so simple, in different circumstances the second row, third row may have \ (2 \) two or \ (4 \) species ......

How to do?

Only Category talk and see what caused the \ (2 \) two or \ (4 \) produce seed in both cases.

The first line: \ ([A, B, C, D] \)

The second line is configured to meet the conditions, is certainly not the first \ (A \) , may be \ (b, c, d \ ) a medium assumed selected \ (B \) , do that the second ?

It may be (a, c, d \) \ a medium, so the difference begins ......

First, choose \ (a \)

If such election, then this line will determine: \ ([b, A, d, c] \)

Look at the features:

\([a,b,c,d]\\ [b,a,d,c]\)

In fact, I found \ (a, b \) exchange, \ (c, d \) exchange.

The ring is transformed into a picture like this:











We gave it a name:对称

This time to determine what the third line.

The first two only put \ (C, D \) , only the third four discharge \ (A, B \) , and the two switching positions the internal solution obtained also satisfies the condition.

Therefore, in this case, there is a third row \ (2 \ times 2 = 4 \) species.

How many such cases do?

4 corresponds to the selected two pairs, but must be noted that, once selected a pair, the other pair is also determined, it is required in addition to 2 weight.

Co \ (\ frac {C_4 ^ 2 } {2} = 3 \) species.

Second, the election \ (C \) or \ (D \)

In fact, these two are equivalent, assuming the election \ (c \) .

That third it?

Seemingly can also choose \ (A, d \) , in fact, can only choose \ (d \) , Why?

If selected from the group \ (A \) , drawn into the ring:









The \ (d \) is isolated out, but the last one can not put \ (d \) , it is not true.

Option \ (D \) , drawn into the ring:











To meet the conditions.

We gave it a name:轮换

\([a,b,c,d]\\ [b,c,d,a]\)

This time to determine what the third line.

We can continue to go along this ring, such as from \ (b \) to \ (c \) , followed by other variants

To obtain a solution: \ ([C, D, A, B] \)

We can skip a go, such as from \ (B \) to \ (D \) , other variations are sequentially jumping

Another solution to give: \ ([D, A, B, C] \) (with respect to the second row is not 对称right ......)

There are only two.

Therefore, in this case, there is a third row \ (2 \) species.

How many such cases do?

This whole transformation is a ring, pick a start, the next there \ (3 \) species, then the next a \ (2 \) species, have selected the ring after conversion is determined.

Co \ (3 \ times 2 = 6 \) species.

to sum up

There are always \ (4! \ Times (\ frac {C_4 ^ 2} {2} \ times 4 + 3 \ times2 \ times2) = 576 \) species.

Guess you like

Origin www.cnblogs.com/spaceskynet/p/11797562.html