This is the solutions that I am able to arrive at.
This generates all the permutations in the order required. but takes
quite a lot of time for 6th generation.
Need to check whether this solution can be optimized more.
public class P2D
{
boolean usedr[][];
boolean usedc[][];
//temp matrix
Thats the solution all right!!!
Sorry for the late reply.
Let me post my solution (You need not know anything about Latin squares to understand this :) )
For N, let me consider a matrix where the first row and column are 1...N
1 2 3 ... N
2
3
.
.
N
Now we can fill the inner matrix using brute force...and find out the number
A clue ( The solution is obviuosly brute force, but look at the two optimizations that reduce the search space by ( n!*(n-1)! ) )-karthik
Hi, I am the guy who set that question :D Look at the huge amount of theory available on Latin Squares. In case you still are not able to get the solution just post it again and I will reply. -karthik