• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 29, 2022 |13.1K Views
Count number of ways to reach a given score in a game
Description
Discussion

Consider a game where a player can score 3 or 5 or 10 points in a move. Given a total score n, find number of ways to reach the given score.
 

Examples: 


Input: n = 20
Output: 4


There are following 4 ways to reach 20
(10, 10)
(5, 5, 10)
(5, 5, 5, 5)
(3, 3, 3, 3, 3, 5)
 

This problem is a variation of coin change problem and can be solved in O(n) time and O(n) auxiliary space.


The idea is to create a table of size n+1 to store counts of all scores from 0 to n. For every possible move (3, 5 and 10), increment values in table.

Count number of ways to reach a given score in a game : https://www.geeksforgeeks.org/count-number-ways-reach-given-score-game/

Read More