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