candies distinct candies (each has its own number) and bags identical bags. Put all the candies into the bags so that no bag is left empty.
The bags are indistinguishable and the order of candies inside a bag does not matter: two arrangements are the same when they group the candies the same way. For example, {1}, {2, 3} and {3, 2}, {1} are the same, while {1}, {2, 3} and {2}, {1, 3} are different.
Return the number of different arrangements modulo 10⁹ + 7.candies=3, bags=3 → 1
Every bag gets exactly one candy, so there is a single way.
candies=4, bags=3 → 6
Two of the candies share a bag and the other two are alone. The pair can be chosen in 6 ways.
candies=5, bags=2 → 15
candies=3, bags=3
1
Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.