Problem Description
There are n performers and x stages. Each performer is assigned to one of the x stages. Performers assigned to the same stage form a band, and empty stages are allowed. After all performances, every non‐empty band receives a score in the range [1, y]. Two events are considered different if at least one performer is assigned to a different stage or if any band (non‐empty stage) is awarded a different score. The task is to calculate the total number of possible events modulo 10^9+7.
Key Insights
- The assignment of performers to stages is independent of the awarding of scores.
- For each assignment, only the occupied (non‐empty) stages receive a score.
- If exactly k stages are non‐empty then there are (binom(x, k) * ways to assign n performers to get exactly k non‐empty stages) ways to assign performers, and each occupied stage can receive y scores.
- Use dynamic programming to compute the number of performer assignments that yield exactly j non‐empty stages, then multiply by y^j for the score choices.
- Recurrence: dp[i+1][j] = j * dp[i][j] (assign performer to an already occupied stage) + (x - j) * dp[i][j] (assign performer to a new stage).
Space and Time Complexity
Time Complexity: O(nx), due to the nested loops over the number of performers and stages. Space Complexity: O(nx) if using a 2D dp table; this can be optimized to O(x) using a single array.
Solution
We solve the problem using dynamic programming. Let dp[i][j] represent the number of ways to assign i performers such that exactly j stages are occupied. When adding a new performer, we have two options:
- Put the performer into one of the already occupied j stages (which gives j choices).
- Assign the performer to one of the remaining (x-j) stages (which will result in a new non‐empty stage).
After processing all performers, for each scenario with j occupied stages, we have y^j ways to award scores to these bands. Sum these results for j from 1 to x to get the final answer (modulo 10^9+7).