Given three integers R, B and W which denote the number of runs, balls and wickets. One can score 0, 1, 2, 3, 4, 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:
- Find ways to arrange K green balls among N balls such that exactly i moves is needed to collect all K green balls
- Ways to arrange Balls such that adjacent balls are of different types
- Ways to choose balls such that at least one ball is chosen
- Number of distinct ways to represent a number as sum of K unique primes
- Find the number of ways to divide number into four parts such that a = c and b = d
- Number of ways to represent a number as sum of k fibonacci numbers
- Number of ways to get a given sum with n number of m-faced dices
- Count number of ways to get Odd Sum
- Ways to represent a number as a sum of 1's and 2's
- Number of ways to pair people
- Number of ways to reach the end of matrix with non-zero AND value
- Number of ways to go from one point to another in a grid
- 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 distribute N Paper Set among M students
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.