From d78017208e24fc46db233a94f56dc155350dce61 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Wed, 27 Dec 2023 09:47:24 -0500 Subject: 1155 --- 1155/main.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 1155/main.py 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() -- cgit v1.2.3