A cricket player has to score N runs, with condition he can take either 1 or 2 runs only and consecutive runs should not be 2. Find all the possible combination he can take.
Input : N = 4 Output : 4 1+1+1+1, 1+2+1, 2+1+1, 1+1+2 Input : N = 5 Output : 6
Source :Oracle Interview On campus
This problem is a variation of count number of ways to reach given score in a game and can be solved in O(n) time and O(n) auxiliary space.
Below is the recursive solution of above problem.
This problem has optimal substructure property as the problem can be solved using solutions to subproblems.
Below is the Dp solution of above problem
- Count number of ways to reach a given score in a game
- Count ways to reach the n'th stair
- Count ways to reach the nth stair using step 1, 2 or 3
- Count number of ways to jump to reach end
- Count number of ways to reach destination in a Maze
- Number of ways to reach Nth floor by taking at-most K leaps
- Count of different ways to express N as the sum of 1, 3 and 4
- Count number of binary strings without consecutive 1's
- Count of arrays having consecutive element with different values
- Count possible ways to construct buildings
- Count ways to increase LCS length of two strings by one
- Count ways to build street under given constraints
- Count ways to express a number as sum of powers
- Count number of ways to cover a distance
- Count number of ways to partition a set into k subsets
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.