返回列表 上一主題 發帖

[發問] 機率問題(EX:39個號碼,五個號碼都在1~19的機率)

回復 1# PKKO
排列組合中  C(n,r)=n!/[r!*(n-r)!] ,!表示階層

五個號碼都出現在1~19,機率 = C(19,5)/C(39,5) = 0.020196
只有四個號碼出現在1~19,機率 =C(19,4)*C(20,1)/C(39,5) = 0.13464
只有三個號碼出現在1~19,機率 =C(19,3)*C(20,2)/C(39,5) = 0.31977
只有兩個號碼出現在1~19,機率 =C(19,2)*C(20,3)/C(39,5) = 0.33858
只有一個號碼出現在1~19,機率 =C(19,1)*C(20,4)/C(39,5) = 0.15989
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

回復 3# PKKO
  1. 'n階層 , return double
  2. Function dblFactorial(n As Integer) As Double
  3.     dblFactorial = 1
  4.     For i = 1 To n
  5.         dblFactorial = dblFactorial * i
  6.     Next
  7. End Function

  8. '組合
  9. Function dblCombination(n As Integer, r As Integer) As Double
  10.     'By formula method:
  11.     dblCombination = dblFactorial(n) / (dblFactorial(r) * dblFactorial(n - r))
  12.    
  13. '    'Speedup method (less multiply computations , allowed larger n):
  14. '    dblCombination = 1
  15. '    For i = 1 To Application.Min(r, n - r)
  16. '        dblCombination = dblCombination * (n - i + 1)
  17. '    Next
  18. '    dblCombination = dblCombination / dblFactorial(Application.Min(r, n - r))
  19. End Function

  20. Sub Test()
  21.     MsgBox "五個號碼都出現在1~19,機率 = " & Format(dblCombination(19, 5) / dblCombination(39, 5), "0.000000")
  22. End Sub
複製代碼
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

        靜思自在 : 要比誰更受誰.不要比誰更怕誰。
返回列表 上一主題