您给我的计算公式没有去处重复的组合呀!就是33个数字的那个.如题 原程序:Sub tt() Application.ScreenUpdating = False Dim i,j,k,l,m,n As Integer Dim Ar(33) As Integer,Arsum As Long,tempSum As Long Dim x As Long Dim FS As Ob
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 23:40:10
您给我的计算公式没有去处重复的组合呀!就是33个数字的那个.如题 原程序:Sub tt() Application.ScreenUpdating = False Dim i,j,k,l,m,n As Integer Dim Ar(33) As Integer,Arsum As Long,tempSum As Long Dim x As Long Dim FS As Ob
您给我的计算公式没有去处重复的组合呀!就是33个数字的那个.如题
原程序:Sub tt() Application.ScreenUpdating = False Dim i,j,k,l,m,n As Integer Dim Ar(33) As Integer,Arsum As Long,tempSum As Long Dim x As Long Dim FS As Object Dim F As Object '文件对象 Set FS = CreateObject("Scripting.FileSystemObject") Set F = FS.CreateTextFile("c:\111.txt",True) For i = 1 To 33 Ar(i) = Cells(i,1) Arsum = Arsum + Ar(i) Next i x = 0 For i = 1 To 28 For j = i + 1 To 29 For k = j + 1 To 30 For l = k + 1 To 31 For m = l + 1 To 32 For n = m + 1 To 33 tempSum = Ar(i) + Ar(j) + Ar(k) + Ar(l) + Ar(m) + Ar(n) If Arsum - tempSum = 140 Then x = x + 1 txt = Ar(i) & "," & Ar(j) & "," & Ar(k) & "," & Ar(l) & "," & Ar(m) & "," & Ar(n) & "," & Arsum - tempSum F.writeline txt End If Next Next Next Next Next Next Application.ScreenUpdating = True MsgBox "共有组合" & x F.Close Set F = Nothing Set FS = Nothing End Sub
您给我的计算公式没有去处重复的组合呀!就是33个数字的那个.如题 原程序:Sub tt() Application.ScreenUpdating = False Dim i,j,k,l,m,n As Integer Dim Ar(33) As Integer,Arsum As Long,tempSum As Long Dim x As Long Dim FS As Ob
什么是重复的组合?应该是不会出现的 比如低烧给的33个初始值中,没有重复的则,不会有重复的组合.这个你可验证,在EXCEL中A列放入1-33,试试.是不会重复的.但是如果你给的33个值中有重复的值,那么就会出现重复组合.如果要避免这个问题.程序修改是没有什么问题的.但是由于程序是用穷举法来算的.为了验证是不是有重复的组合.需要先对每种组合进行排序(你给的33个数可能是无序的),然后保存起来.然后再用每一种新组合和已经生成的组合进行比对,程序的运算量会是天文数字.程序的执行时间会非常长.个人觉得会很长.33个数取6个,共有100多万种组合.如果每一种生组合都要在已经有的组合中检查一下是否重复,你自己想一下有多少种.