Given two positive integers N and M, the task is to find the number of ways to place M distinct objects in partitions of even indexed boxes which are numbered [1, N] sequentially, and every ith Box has i distinct partitions. Since the answer can be very large, print modulo 1000000007.
Input: N = 2, M = 1 Output: 2 Explanation: Since, N = 2. There is only one even indexed box i.e box 2, having 2 partitions. Therefore, there are two positions to place an object. Therefore, number of ways = 2.
Input: N = 5, M = 2 Output: 32
Approach: Follow the steps below to solve the problem:
M objects are to be placed in even indexed box’s partitions. Let S be the total even indexed box’s partitions in N boxes.
The number of partitions is equal to the summation of all even numbers up to N. Therefore, Sum, S = X * (X + 1), where X = floor(N / 2).
Each object can occupy one of S different positions. Therefore, the total number of ways = S*S*S..(M times) =SM.
Below is the implementation of the above approach:
Please Login to comment...