从集合﹛1.2.3.4.5.6.7.8.9.10﹜中选出由5个数组成的任何两个数的和不等于11 。 10
网上的答案是2的五次方,
1.为什么1和10,2和9。。。这样的组合每组只能组成两种子集比如1不就能组成1.2.3.4.5,1.9.8.7.6 这两种吗,难道是怕重复?求解释详细一点!
:2就算每组只有两种情况吧,那为什么五组不是2×5而是2的五次方??求解! 展开
用如下VBA程序,在A1:A32列出了所有满足条件的组合:
Sub try()
Dim i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer, i5 As Integer
Dim k As Integer
Range("A:A").ClearContents
k = 1
For i1 = 1 To 6
For i2 = i1 + 1 To 7
For i3 = i2 + 1 To 8
For i4 = i3 + 1 To 9
For i5 = i4 + 1 To 10
If i1 + i2 <> 11 And i1 + i3 <> 11 And i1 + i4 <> 11 And i1 + i5 <> 11 And i2 + i3 <> 11 And i2 + i4 <> 11 And i2 + i5 <> 11 And i3 + i4 <> 11 And i3 + i5 <> 11 And i4 + i5 <> 11 Then
Range("A" & k) = i1 & " " & i2 & " " & i3 & " " & i4 & " " & i5
k = k + 1
End If
Next i5
Next i4
Next i3
Next i2
Next i1
End Sub
计算结果如图: