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(5, 4)
  18. print(f"9D 第 9 项:{result}")
  19.  
Success #stdin #stdout 0.03s 9688KB
stdin
Standard input is empty
stdout
9D 第 9 项:56