fork download
  1. def simplex_number(d, n):
  2. # 动态规划表
  3. dp = [[0] * (n + 1) for _ in range(d + 1)]
  4.  
  5. # 初始化一维简单形数
  6. for i in range(1, n + 1):
  7. dp[1][i] = i
  8.  
  9. # 动态递推
  10. for dim in range(2, d + 1):
  11. for num in range(1, n + 1):
  12. dp[dim][num] = dp[dim][num - 1] + dp[dim - 1][num]
  13.  
  14. return dp[d][n]
  15.  
  16. # 示例:计算五维的第 4 项
  17. result = simplex_number(1000, 150)
  18. print(f"5D 第 4 项:{result}")
  19.  
Success #stdin #stdout 0.11s 23528KB
stdin
Standard input is empty
stdout
5D 第 4 项:111477784379677834472313244873201322701681154047969408751556961104009925661153309098246830353533320654733998144143971649755262156496878387073360360706112006943818088813853325835034640542647384