Given three integers R, B and W which denote the number of runs, balls and wickets. One can score 0, 1, 2, 3, 6 or a wicket in a single ball in a cricket match. The task is to count the number of ways in which a team can score exactly R runs in exactly B balls with at-most W wickets. Since the number of ways will be large, print the answer modulo 1000000007.
Input: R = 4, B = 2, W = 2
The 7 ways are:
Input: R = 40, B = 10, W = 4
- If a team scores 1 run off a ball then runs = runs + 1 and balls = balls + 1.
- If a team scores 2 runs off a ball then runs = runs + 2 and balls = balls + 1.
- If a team scores 3 runs off a ball then runs = runs + 3 and balls = balls + 1.
- If a team scores 4 runs off a ball then runs = runs + 4 and balls = balls + 1.
- If a team scores 6 runs off a ball then runs = runs + 6 and balls = balls + 1.
- If a team scores no run off a ball then runs = runs and balls = balls + 1.
- If a team loses 1 wicket off a ball then runs = runs and balls = balls + 1 and wickets = wickets + 1.
The DP will consist of three states, with the run state being a maximum of 6 * Balls, since it is the maximum possible. Hence dp[i][j][k] denotes the number of ways in which i runs can be scored in exactly j balls with losing k wickets.
Below is the implementation of the above approach:
- Ways to arrange Balls such that adjacent balls are of different types
- Number of ways to represent a number as sum of k fibonacci numbers
- Find the number of ways to divide number into four parts such that a = c and b = d
- Ways to represent a number as a sum of 1's and 2's
- Number of ways to pair people
- Number of ways to go from one point to another in a grid
- Number of ways to reach the end of matrix with non-zero AND value
- Number of ways to get even sum by choosing three numbers from 1 to N
- Number of ways to swap two bit of s1 so that bitwise OR of s1 and s2 changes
- Number of ways to arrange N items under given constraints
- Count ways to express even number ‘n’ as sum of even integers
- Count the number of ways to traverse a Matrix
- Number of ways to cut a stick of length N into K pieces
- Count number of ways to jump to reach end
- Bell Numbers (Number of ways to Partition a Set)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.