高手,小弟用vb没用剪枝30个数就花去将近2分钟。你的程序很快,厉害!
这是小弟的代码,相当愚昧。
Private Sub Command1_Click()
Dim i0 As long
Dim i1 As long
Dim i2 As long
Dim i3 As long
Dim i4 As long
Dim i5 As long
Dim i6 As long
Dim i7 As long
Dim i8 As long
Dim i9 As long
Dim i10 As long
Dim i11 As long
Dim i12 As long
Dim i13 As long
Dim i14 As long
Dim i15 As long
Dim i16 As long
Dim i17 As long
Dim i18 As long
Dim i19 As long
Dim i20 As long
Dim i21 As long
Dim i22 As long
Dim i23 As long
Dim i24 As long
Dim i25 As long
Dim i26 As long
Dim i27 As long
Dim i28 As long
Dim i29 As long
Dim a0 As Double
Dim a1 As Double
Dim a2 As Double
Dim a3 As Double
Dim a4 As Double
Dim a5 As Double
Dim a6 As Double
Dim a7 As Double
Dim a8 As Double
Dim a9 As Double
Dim a10 As Double
Dim a11 As Double
Dim a12 As Double
Dim a13 As Double
Dim a14 As Double
Dim a15 As Double
Dim a16 As Double
Dim a17 As Double
Dim a18 As Double
Dim a19 As Double
Dim a20 As Double
Dim a21 As Double
Dim a22 As Double
Dim a23 As Double
Dim a24 As Double
Dim a25 As Double
Dim a26 As Double
Dim a27 As Double
Dim a28 As Double
Dim a29 As Double
Dim aa As Double
Dim aa1 As Double
Dim bb As String
Dim tt As Long
a0 = Val(Text1(0))
a1 = Val(Text1(1))
a2 = Val(Text1(2))
a3 = Val(Text1(3))
a4 = Val(Text1(4))
a5 = Val(Text1(5))
a6 = Val(Text1(6))
a7 = Val(Text1(7))
a8 = Val(Text1(8))
a9 = Val(Text1(9))
a10 = Val(Text1(10))
a11 = Val(Text1(11))
a12 = Val(Text1(12))
a13 = Val(Text1(13))
a14 = Val(Text1(14))
a15 = Val(Text1(15))
a16 = Val(Text1(16))
a17 = Val(Text1(17))
a18 = Val(Text1(18))
a19 = Val(Text1(19))
a20 = Val(Text1(20))
a21 = Val(Text1(21))
a22 = Val(Text1(22))
a23 = Val(Text1(23))
a24 = Val(Text1(24))
a25 = Val(Text1(25))
a26 = Val(Text1(26))
a27 = Val(Text1(27))
a28 = Val(Text1(28))
a29 = Val(Text1(29))
aa1 = Val(Text1(31))
For i29 = 0 To 1
For i28 = 0 To 1
For i27 = 0 To 1
For i26 = 0 To 1
For i25 = 0 To 1
For i24 = 0 To 1
For i23 = 0 To 1
For i22 = 0 To 1
For i21 = 0 To 1
For i20 = 0 To 1
For i19 = 0 To 1
For i18 = 0 To 1
For i17 = 0 To 1
For i16 = 0 To 1
For i15 = 0 To 1
For i14 = 0 To 1
For i13 = 0 To 1
For i12 = 0 To 1
For i11 = 0 To 1
For i10 = 0 To 1
For i9 = 0 To 1
For i8 = 0 To 1
For i7 = 0 To 1
For i6 = 0 To 1
For i5 = 0 To 1
For i4 = 0 To 1
For i3 = 0 To 1
For i2 = 0 To 1
For i1 = 0 To 1
For i0 = 0 To 1
aa = a0 * i0 + a1 * i1 + a2 * i2 + a3 * i3 + a4 * i4 + a5 * i5 + a6 * i6 + a7 * i7 + a8 * i8 + a9 * i9 + a10 * i10 + a11 * i11 + a12 * i12 + a13 * i13 + a14 * i14 + a15 * i15 + a16 * i16 + a17 * i17 + a18 * i18 + a19 * i19 + a20 * i20 + a21 * i21 + a22 * i22 + a23 * i23 + a24 * i24 + a25 * i25 + a26 * i26 + a27 * i27 + a28 * i28 + a29 * i29
If aa = aa1 Then
bb = a0 & "*" & i0 & "+" & a1 & "*" & i1 & "+" & a2 & "*" & i2 & "+" & a3 & "*" & i3 & "+" & a4 & "*" & i4 & "+" & a5 & "*" & i5 & "+" & a6 & "*" & i6 & "+" & a7 & "*" & i7 & "+" & a8 & "*" & i8 & "+" & a9 & "*" & i9 & "+" & a10 & "*" & i10 & "+" & a11 & "*" & i11 & "+" & a12 & "*" & i12 & "+" & a13 & "*" & i13 & "+" & a14 & "*" & i14 & "+" & a15 & "*" & i15 & "+" & a16 & "*" & i16 & "+" & a17 & "*" & i17 & "+" & a18 & "*" & i18 & "+" & a19 & "*" & i19 & "+" & a20 & "*" & i20 & "+" & a21 & "*" & i21 & "+" & a22 & "*" & i22 & "+" & a23 & "*" & i23 & "+" & a24 & "*" & i24 & "+" & a25 & "*" & i25 & "+" & a26 & "*" & i26 & "+" & a27 & "*" & i27 & "+" & a28 & "*" & i28 & "+" & a29 & "*" & i29 & "=" & aa1
bb = Replace(bb, "+0*0", "")
bb = Replace(bb, "*1", "")
bb = Replace(bb, Val(Text1(0)) & "*0+", "")
For i = 0 To 29
bb = Replace(bb, "+" & Val(Text1(i)) & "*0", "")
Next
Text1(30) = bb
Exit Sub
End If
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Next
Dim a1,a2,a3...... as Double
这样是很不规范的写法!
其实你这样写只是定义了最后一个变量!!!
没有定义变量,编译后运行的速度会很慢!!!
为的只是增加编译后运行的速度,不定义会很慢的!
不好意思。
前面 Dim i1 as Double.......Dim i29 as Double
应为 Dim i1 as Long .......Dim i29 as Long
Double是双精度,为了支持小数。
当然我的方法只是很笨的一个方法,即所有的组合都用上了,效率很低!!!