Count Ways to Score in a Game#
Consider a game where players can score 3, 5, or 10 points in a move. Given a total score of N, The task is to find the number of ways to reach the given score.
Examples:
Input: n = 20 Output: 4 Explanation: There are following 4 ways to reach 20: (10, 10), (5, 5, 10), (5, 5, 5, 5), (3, 3, 3, 3, 3, 5)
Input: n = 13 Output: 2 Explanation: There are following 2 ways to reach 13: (3, 5, 5), (3, 10)
def countWays(n: int) -> int:
ways = [0] * (n + 1)
ways[0] = 1
moves = [3, 5, 10]
for i in range(3):
for j in range(moves[i], n+1):
ways[j] += ways[j - moves[i]]
return ways[n]
countWays(20)
4