fork download
  1. from functools import lru_cache
  2. class Solution:
  3. def numOfArrays(self, n: int, m: int, k: int) -> int:
  4. if k>m:
  5. return 0
  6. @lru_cache
  7. def sol(i,ct,curr):
  8. if i==n:
  9. if ct==k and curr<=m:
  10. return 1
  11. return 0
  12.  
  13. if ct>k or curr>m:
  14. return 0
  15.  
  16.  
  17. t1=sol(i+1,ct+1,curr+1)
  18. t2=sol(i,ct,curr+1)
  19. if i!=0:
  20. t3=sol(i+1,ct,curr)
  21. else:
  22. t3=0
  23.  
  24. return (t1+t2+t3)%(10**9+7)
  25. return sol(0,0,0)
Success #stdin #stdout 0.08s 14144KB
stdin
Standard input is empty
stdout
Standard output is empty