Given three numbers N, A, B. The task is to count the number of ways to select things such that there exists no set of size either A or B. Answer can be very large. So, output answer modulo 109+7.
Note: Empty set is not consider as one of the way.
Input: N = 4, A = 1, B = 3
The number of ways to form sets of size 2 are 6 (4C2).
The number of ways to form sets of size 4 are 1 (4C4).
Input: N = 10, A = 4, B = 9
Approach: The idea is to first find the number of ways including sets of size including A, B and empty sets. Then the remove the number of the sets of size A, B and empty sets.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Number of ways to cut a stick of length N into K pieces
- Factorial of a large number
- Print all distinct permutations of a given string with duplicates
- How to find Lexicographically previous permutation?
- Find all distinct subsets of a given set
- Number of ways to make mobile lock pattern
- Count ways to spell a number with repeated digits
- Paper Cut into Minimum Number of Squares
- Ways to represent a number as a sum of 1's and 2's
- Number of distinct permutation a String can have
- Ways to sum to N using array elements with repetition allowed
- Count number of strings (made of R, G and B) using given combination
- Maximum number of 3-person teams formed from two groups
- Get the kth smallest number using the digits of the given number
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Find n-th lexicographically permutation of a string | Set 2
- Make all combinations of size k
- Number of bitonic arrays of length n and consisting of elements from 1 to n
- Counting pairs when a person can form pair with at most one
- Rearrangement of a number which is also divisible by it
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.