There are 25 "ones" arranged in a 5*5 matrix.
You are requested to erase n ones leaving a matrix in which the quantities of "ones" in each column and each row are divisible by 3.
How many distinct solutions are there, provided you do not erase the "one" in the upper left corner?
(In reply to
re: solution - what about these? by Brian Smith)
10011
01110
11100
01011
10101
10101
01101
11100
00000
11001
10101
10101
01110
01011
11010
10101
10110
00111
10011
00000
10110
01011
01101
10011
11100
10110
11010
10101
01011
01101
11001
01110
10110
00111
11001
11010
01101
10011
01110
10101
11010
01110
11001
10101
00111
11100
10011
00111
01101
11010
11100
11010
01011
00111
10101
The above are a sampling of the 1548 arrays that match what is asked for. BTW, without the proviso that the upper-left corner remain a 1, there'd be a total of 2741 arrays.
DefDbl A-Z
Dim crlf$, vline(11) As String * 5
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
vline(0) = "00000"
vline(1) = "00111"
vline(2) = "01011"
vline(3) = "01101"
vline(4) = "01110"
vline(5) = "10011"
vline(6) = "10101"
vline(7) = "10110"
vline(8) = "11001"
vline(9) = "11010"
vline(10) = "11100"
For r1 = 0 To 10
For r2 = 0 To 10
For r3 = 0 To 10
For r4 = 0 To 10
For r5 = 0 To 10
good = 1
For col = 1 To 5
tot = Val(Mid(vline(r1), col, 1)) + Val(Mid(vline(r2), col, 1)) + Val(Mid(vline(r3), col, 1)) + Val(Mid(vline(r4), col, 1)) + Val(Mid(vline(r5), col, 1))
If tot <> 0 And tot <> 3 Then good = 0: Exit For
Next
If good Then
ct = ct + 1
If Left(vline(r1), 1) = "1" Then
ct2 = ct2 + 1
If Rnd(1) < 1 / 80 Then
Text1.Text = Text1.Text & vline(r1) & crlf
Text1.Text = Text1.Text & vline(r2) & crlf
Text1.Text = Text1.Text & vline(r3) & crlf
Text1.Text = Text1.Text & vline(r4) & crlf
Text1.Text = Text1.Text & vline(r5) & crlf
Text1.Text = Text1.Text & crlf
End If
End If
End If
Next
Next
Next
Next
Next
Text1.Text = Text1.Text & crlf & ct2 & Str(ct) & " done"
End Sub
|
Posted by Charlie
on 2016-02-18 13:50:04 |