fork download
  1. import math
  2.  
  3. def nCr(n,r):
  4. f = math.factorial
  5. return (f(n) / (f(r) / f(n-r)))
  6.  
  7. t=input()
  8. for _ in range(0,t):
  9.  
  10. s=raw_input().split()
  11.  
  12. s,n,m,k=int(s[0]),int(s[1]),int(s[2]),int(s[3])
  13.  
  14. y=float(0.000000)
  15.  
  16. total = nCr(s-1,n-1)
  17.  
  18. if s==n:
  19. print("1.000000")
  20. continue
  21.  
  22. if k>n:
  23. print"0.000000\n"
  24. continue
  25.  
  26. s=s-1
  27. n=n-1
  28. m=m-1
  29.  
  30. for i in range(0,k):
  31. q=nCr(m,i)
  32. w=nCr(s-m,n-i)
  33. y+=(q*w)
  34.  
  35. print (float(1-y/total))
Runtime error #stdin #stdout #stderr 0.01s 7732KB
stdin
3
10 10 5 3
10 4 6 4
3 2 2 1
stdout
1.000000
stderr
Traceback (most recent call last):
  File "prog.py", line 16, in <module>
    total = nCr(s-1,n-1)
  File "prog.py", line 5, in nCr
    return (f(n) / (f(r) / f(n-r)))
ZeroDivisionError: integer division or modulo by zero