Problem Description
You are given three integers n
, x
, and y
. An event is being held for n
performers. When a performer arrives, they are assigned to one of the x
stages. All performers assigned to the same stage will perform together as a band, though some stages might remain empty. After all performances are completed, the jury will award each band a score in the range [1, y]
. Return the total number of possible ways the event can take place. Since the answer may be very large, return it modulo 10^9 + 7
.
Key Insights
- Each performer can be assigned to one of the
x
stages, leading tox^n
possible assignments. - Each band created (which corresponds to a unique stage) can receive a score from
1
toy
, resulting iny^k
possible score combinations, wherek
is the number of non-empty stages. - The total number of configurations must consider all possible non-empty stage combinations, which can be calculated using the principle of inclusion-exclusion.
- The final answer is calculated as the product of the total assignments and the score configurations, adjusted for the empty stages.
Space and Time Complexity
Time Complexity: O(n * x)
Space Complexity: O(1)
Solution
To solve the problem, we first need to calculate the number of ways to assign n
performers to x
stages, which is x^n
. Next, we need to determine the number of ways to score the bands formed by the assigned performers. This requires calculating how many non-empty subsets of stages can be formed. We can use the principle of inclusion-exclusion to count all possible combinations of scores based on the number of non-empty stages.
Steps:
- Calculate
total_assignments = x^n % (10^9 + 7)
. - For each possible number of non-empty stages
k
(from1
tox
), calculate the number of ways to choosek
stages fromx
and the number of ways to assign scores from1
toy
to thosek
stages. - Sum the results for
k
from1
tox
.