-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path1155.py
23 lines (20 loc) · 878 Bytes
/
1155.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
__________________________________________________________________________________________________
class Solution:
def numRollsToTarget(self, d: int, f: int, target: int) -> int:
mem = {}
def get_num(*args):
if args in mem:
return mem[args]
n, t = args
if t < n or t > n * f:
return 0
if n == 0:
return 1 if t == 0 else 0
result = sum(
get_num(n - 1, t - i) for i in range(1, f + 1)
) % 1000000007
mem[args] = result
return result
return get_num(d, target)
__________________________________________________________________________________________________
__________________________________________________________________________________________________