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