TShopping

標題: Python math.comb() 如何算出來 [打印本頁]

作者: woff    時間: 2021-1-7 15:02
標題: Python math.comb() 如何算出來
就是高中數學的那個排列組合的組合,C。從 n 樣東西里,取出 m 樣,計算有幾種取法
就是那個組合的 nCm
公式寫出來就是 n!/( (n-m)!*m! )
wiki 介紹
  1. # Import math Library
  2. import math

  3. # Initialize the number of items to choose from
  4. n = 7

  5. # Initialize the number of possibilities to choose
  6. k = 5

  7. # Print total number of possible combinations
  8. print (math.comb(n, k))
複製代碼
The result will be:

21






歡迎光臨 TShopping (http://www.tshopping.com.tw/) Powered by Discuz! X3.2