aboutsummaryrefslogtreecommitdiffstats
path: root/1155
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2023-12-27 14:47:24 +0000
committerterminaldweller <devi@terminaldweller.com>2023-12-27 14:47:24 +0000
commitd78017208e24fc46db233a94f56dc155350dce61 (patch)
treedeff930f5b0cadd378223b20355c08fce421be5c /1155
parent91 (diff)
downloadleetcode-d78017208e24fc46db233a94f56dc155350dce61.tar.gz
leetcode-d78017208e24fc46db233a94f56dc155350dce61.zip
1155
Diffstat (limited to '1155')
-rwxr-xr-x1155/main.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/1155/main.py b/1155/main.py
new file mode 100755
index 0000000..c0af065
--- /dev/null
+++ b/1155/main.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+
+from functools import lru_cache
+
+
+class Solution:
+ @lru_cache(None)
+ def numRollsToTarget(self, d: int, f: int, target: int) -> int:
+ if d == 1:
+ if 0 < target <= f:
+ return 1
+ return 0
+ if target < d or target > f * d:
+ return 0
+ res = 0
+ for i in range(1, f + 1):
+ res += self.numRollsToTarget(d - 1, f, target - i) % (10**9 + 7)
+ return res % (10**9 + 7)
+
+
+def main():
+ solution = Solution()
+ print(solution.numRollsToTarget(1, 6, 3))
+ print(solution.numRollsToTarget(2, 6, 7))
+ print(solution.numRollsToTarget(2, 5, 10))
+ print(solution.numRollsToTarget(30, 30, 500))
+
+
+if __name__ == "__main__":
+ main()