Hello
I am working on java and I have to generate all the possible patterns(combinations) of M-by-N matrices such that in the same row there should not be more than a single 1, Same column may contain more than a single 1, Taking an example of 3*3 matrix, matrices generated should look like:
1 0 0
1 0 0
1 0 0
0 1 0
1 0 0
1 0 0
0 0 1
1 0 0
1 0 0
1 0 0
0 1 0
1 0 0
1 0 0
0 0 1
1 0 0
1 0 0
1 0 0
0 1 0
1 0 0
1 0 0
0 0 1
0 1 0
0 1 0
0 1 0
1 0 0
0 1 0
0 1 0
0 0 1
0 1 0
0 1 0
0 1 0
1 0 0
0 1 0
0 1 0
0 0 1
0 1 0
….. and so on.
As I have already said that progrom should be flexible that can generate all such possible patterns for any value of M and N.
Please help me..
Thanks!
Here’s one solution. ideone.com demo.
I bet it can be done with half the number of rows though.
Output for the 2×3 case: