Find number of ways to select subset with distinct objects of at most K size.

380 Views Asked by At

I have a set of x number of 'A' type object, y number of 'B' type object and z number of 'C' type object. Now, I need to find the number of subsets of atmost 'k' size that can be made such that all the objects in subsets are distinct. No two same type of object will be in the same subset. The elements are same but their combinations are considered different.

Eg:- [1,1,5,5,4] and k = 3

Output:- 17

Explanation:-

[1], [1], [5], [5], [4] => 5

[1,5], [1,5], [1,5], [1,5], [1,4], [1,4], [5,4], [5,4] => 8

[1,5,4], [1,5,4], [1,5,4], [1,5,4] => 4

1

There are 1 best solutions below

4
On BEST ANSWER

The number of subsets with one element is $x+y+z$. The number with two elements is $xy+xz+yz$. The number with three elements is $xyz$. The number with more than three elements is $0$.