Find the number of ways to reach a given score in a game

Find the number of ways to reach a given score in a game

The program to find the number of ways to reach a given score in a game is discussed here. Consider a game where a player can score 1 or 2 or 5 points in a move. Given a total score n, find the total number of ways to reach the given score.


Finding the number of ways to reach a given score in a game

Example 1:

cost = 19

Points per move = 2, 7, 10

Number of ways = 2

  • (2, 7, 10)
  • (2, 2, 2, 2, 2, 2 , 7)


Example 2:

cost = 15

Points per move =5, 10

Number of ways = 2

  • (5, 5, 5)
  • (5, 10)


Finding the number of ways to reach a given score in a game

Algorithm to find the number of ways to reach a given score in a game

  • Input the total score.
  • Input the points per move in an array.
  • The idea is to create an array of size n+1 and store counts of all scores from 0 to n.
  • For every possible move, increment values in the array.

Program to find the number of ways to reach a given score in a game

@@coding::1@@


Finding the number of ways to reach a given score in a game



Finding the number of ways to reach a given score in a game

c