File tree Expand file tree Collapse file tree 4 files changed +24
-24
lines changed Expand file tree Collapse file tree 4 files changed +24
-24
lines changed Original file line number Diff line number Diff line change 1
- 3
1
+ 5
2
+ 2 2
2
3
2 1
3
4
1 1
4
5
10 0
6
+ 12 45
Original file line number Diff line number Diff line change 8
8
10 0
9
9
10
10
'''
11
- import math
12
-
11
+ from math import factorial
12
+ import sys
13
+ sys .setrecursionlimit (50000 )
13
14
tn = int (input ())
14
15
15
16
memo = {}
16
- def solve (player , rn , gn ):
17
- n = rn + gn
18
- if (player , rn , gn ) in memo :
19
- return memo [player , rn , gn ]
20
- if n <= 1 :
21
- return 0
22
- c1 , c2 = 0 , 0
23
- if player == 1 :
24
- c1 = rn * (n - 1 )
25
- c2 = solve (2 , rn , gn - 1 )
26
- elif player == 2 :
27
- c1 = gn * (n - 1 )
28
- c2 = solve (1 , rn - 1 , gn )
29
- memo [player , rn ,gn ] = c1 + c2
30
- return c1 + c2
31
17
18
+ def solve (r , g ):
19
+ if g == 0 and r > 0 or r == 0 and g > 0 :
20
+ return 1.0
21
+ if g < 0 or r < 0 :
22
+ return 0.0
23
+ n = r + g - 1
24
+ now = factorial (n )// (factorial (r - 1 ))
25
+ now //= factorial (g )
26
+ return now + solve (r - 1 , g - 2 )
27
+
32
28
for i in range (tn ):
29
+ memo = {}
33
30
r , g = list (map (int , input ().split ()))
34
- if r == 0 or g == 0 :
35
- print (1.0 )
36
- continue
37
- x = solve (1 , r , g )
38
- print (round (x / math .factorial (r + g ), 6 ))
39
-
31
+ x = solve (r , g )
32
+ sl_sp = factorial (r + g )// factorial (r )
33
+ sl_sp //= factorial (g )
34
+ #print(x, sl_sp)
35
+ print (x / sl_sp )
36
+ #print(round(x/sl_sp, 6))
37
+ print ("-----------------------------" )
You can’t perform that action at this time.
0 commit comments