如题:       
      
                    int     a     =     11;       
                    int[]     x     =     new     int[]{2,7,5,3,4};       
      
                    求     11     =     2     +     5     +     4;或者     11     =     7     +     4; 
好久没来了,顺便向坚守vb的人们致敬......

解决方案 »

  1.   

    只是用vb.net说明一下,用什么无所谓,主要是算法
      

  2.   

    对象:
    Form1
    Text1
    Command1
    Command2
    Option ExplicitType Ntype
    Num As Integer
    Select As Boolean
    End TypePublic N() As Ntype
    Public Pointer As IntegerPublic Function ShowSNum() As String '显示已选的数
    Dim I As Integer, tmp As String
    For I = 1 To Pointer
    If N(I - 1).Select Then
      tmp = tmp & Str(N(I - 1).Num) & " "
    End If
    Next I
    ShowSNum = tmp
    End FunctionPublic Function NSelect() As Integer '已选数的个数
    Dim I As Integer, S As Integer
    S = 0
    For I = 1 To Pointer
    If N(I - 1).Select Then
      S = S + 1
    End If
    Next I
    NSelect = S
    End FunctionPublic Function ShowAll(P As Integer) As String '显示函数
    Dim I As Integer
    If NSelect = 10 Then
    ShowAll = ShowSNum + Chr(13) + Chr(10)
    Else
    For I = P To Pointer '体现选择的单向性,因为是组合不是排列
      N(I - 1).Select = True
      Form1.Text1.SelText = ShowAll(I + 1) '用一个文本框保存结果
      N(I - 1).Select = False
    Next I
    End If
    End Function
    Private Sub Command1_Click()
    Dim I As Integer
    Pointer = InputBox("想生成几个数据?", "Input Number")
    ReDim N(Pointer - 1)
    N(0).Num = Int(Rnd(1) * 10)
    N(0).Select = False
    Text1.SelText = Str(N(0).Num) & " "
    For I = 1 To Pointer - 1
    N(I).Num = N(I - 1).Num + Int(Rnd(1) * 5 + 1)
    N(I).Select = False
    Text1.SelText = Str(N(I).Num) & " "
    Next I
    Text1.SelText = Chr(13) & Chr(10)
    End SubPrivate Sub Command2_Click()
    ShowAll (1)
    End Sub
      

  3.   

    Private Sub Command1_Click()
        Dim num(1 To 10) As Long
        Dim i As Long
        For i = 1 To 10
            num(i) = i
        Next
        
        For i = 1 To 10
            SumX CStr(num(i)), num(i), 11, i + 1, num
        Next
    End SubPrivate Sub SumX(strPre As String, nOp1 As Long, nSum As Long, nStart As Long, aArr() As Long)
        Dim i As Long
        For i = nStart To UBound(aArr)
            If nOp1 + aArr(i) = nSum Then
                Debug.Print strPre & "+" & CStr(aArr(i)) & "=" & CStr(nSum)
            End If
            
            SumX strPre & "+" & CStr(aArr(i)), nOp1 + aArr(i), nSum, i + 1, aArr()
        Next
    End Sub