Find Combinations for Game Scoring
Find the number of ways a player can score n runs.
Statement
Imagine a game where, in each turn, a player can score either or runs. Given a score, n
, find the total number of ways to score n
runs.
Examples
To score runs, a player can score in the following three ways:
To score runs, a player can score in the following ten ways:
Sample input
5
Expected output
10
Try it yourself
#include <iostream>#include <vector>using namespace std;// Scoring options are 1, 2, and 4int ScoringOptions(int n) {// TODO: Write - Your - Codereturn -1;}
Solution 1: Recursion
We can only score , , or points in this game. To reach a score of , we can only use increments of ...
Access this course and 1400+ top-rated courses and projects.