Hi
Ich mache mal einen Vorschlag, ist allerdings VB-Code
Private Sub bestand()
Dim arrBestand
arrBestand = Array(28, 17, 16, 15, 7, 3, 2, 1, 1)
Dim i As Integer
For i = LBound(arrBestand) To UBound(arrBestand)
Call bestandSum(arrBestand, 30, 0, i, "")
Next
End Sub
Private Sub bestandSum(arrBestand, intBedarf As Integer, _
intSum As Integer, intNextElmt As Integer, _
strResultList As String)
Dim i As Integer
Dim sumH As Integer
For i = intNextElmt To UBound(arrBestand)
sumH = intSum + arrBestand(i)
If sumH = intBedarf Then
Debug.Print strResultList & arrBestand(i)
Else
If sumH < intBedarf Then _
Call bestandSum(arrBestand, intBedarf, sumH, i + 1, _
strResultList & arrBestand(i) & ", ")
End If
Next
End Sub
Und der erzeugt folgende Werte:
28, 2
28, 1, 1
17, 7, 3, 2, 1
17, 7, 3, 2, 1
16, 7, 3, 2, 1, 1
17, 7, 3, 2, 1
17, 7, 3, 2, 1
16, 7, 3, 2, 1, 1
16, 7, 3, 2, 1, 1
Und das müssten alle Lösungen sein.
Herzliche Grüße
Wolfgang