Mislim da ce ovo biti resenje problema. Pogledaj primer u prilogu koji
za date kvote utakmica i odabrani sistem (ogranicio sam ga na 10
dogadjaja) racuna dobitak.
Poenta je u funkciji koja racuna sve kombinacije, a zatim izmnozimo
date kvote i saberemo dobijene proizvode. Na kraju sve to podelimo
sa brojem kobinacija (pod uslovom da sam ja dobro shvatio kako
kladionice racunaju dobitke).
Funckija MChooseN je primer rekurzivne funkcije koja pronalazi sve
kombinacije bez ponavljanja, zatim prodjemo kroz celu kolekciju i
izracunamo dobitak. Iskreno, ne secam se vise odakle sam je "pokupio"
da navedem ime autora.
Mogli bismo ovo dalje da razradimo i da uvedemo odabiranje onih
utakmica koje su pogodjene pa da racunamo ne samo maksimalan vec
i realan dobitak, da dodamo cenu po kombinaciji i da izracunamo sve
to u dinarima...
Pozdrav
P.S. Evo koda koji je upisan u Modulu...
Code:
Public Function Dobitak() As Single
Dim M As Integer
Dim N As Integer
Dim I As Integer
Dim J As Integer
Dim solutions As Collection
Dim txt As String
Dim Total As Single
Dim subtotal As Single
Application.Volatile
Total = 0
Set solutions = New Collection
M = [sheet1!e2]
N = [sheet1!e1]
MchoseN N, 1, M, solutions
For I = 1 To solutions.Count
txt = txt & solutions(I) & vbCrLf
subtotal = 1
For J = 1 To N
subtotal = subtotal * [Sheet1!B1].Offset(Mid(solutions(I), (J - 1) * 2 + 1, 2), 0).Range("A1").Value
Next J
' Debug.Print solutions(I) & " = " & subtotal
Total = Total + subtotal
Next I
' Debug.Print "Total = " & Total
Dobitak = Total / [sheet1!e3]
End Function
Private Sub MchoseN(ByVal N As Integer, ByVal first_allowed As Integer, ByVal last_allowed As Integer, ByVal solutions As Collection)
Dim I As Integer
Dim txt As String
Dim partial_solutions As Collection
' If N < 1, we don't need to pick any more
' items.
' If N > last_allowed - first_allowed + 1,
' there are too few items for a solution.
' If N = last_allowed - first_allowed + 1,
' all the items must be in the solution.
If N < 1 Then
' We don't need to pick any more.
' Do nothing.
ElseIf N > last_allowed - first_allowed + 1 Then
' There are not enough items.
' Do nothing.
ElseIf N = last_allowed - first_allowed + 1 Then
' All the items must be in the solution.
txt = Format$(first_allowed, "00")
For I = first_allowed + 1 To last_allowed
txt = txt & Format$(I, "00")
Next I
solutions.Add txt
Else
' Get solutions containing first_allowed.
Set partial_solutions = New Collection
If N = 1 Then
partial_solutions.Add ""
Else
MchoseN N - 1, first_allowed + 1, last_allowed, partial_solutions
End If
' Add first_allowed to make the full
' solutions.
For I = 1 To partial_solutions.Count
solutions.Add Format$(first_allowed, "00") & _
partial_solutions(I)
Next I
' Get solutions not containing first_allowed.
Set partial_solutions = New Collection
MchoseN N, first_allowed + 1, last_allowed, partial_solutions
' Add these to the solutions.
For I = 1 To partial_solutions.Count
solutions.Add partial_solutions(I)
Next I
End If
End Sub