Ctrl K

Festival Stages and Scores

Hard
A festival has musicians performers arriving and stages stages on site. Each arriving musician is sent to one of the stages. Everyone on the same stage performs together as one band; some stages may stay empty. After the show, the jury gives every band (that is, every non-empty stage) a rating, an integer from 1 to max_rating. Two festival outcomes differ if at least one musician ended up on a different stage or at least one band got a different rating. How many outcomes are possible? The answer can be huge, so return it modulo 10⁹ + 7.
Example 1
musicians=2, stages=2, max_rating=2 → 12

If both musicians share a stage (2 ways), there is one band and 2 possible ratings: 4 outcomes. If they are on different stages (2 ways), there are two bands rated 2 · 2 = 4 ways: 8 outcomes. 12 in total.

Example 2
musicians=3, stages=1, max_rating=5 → 5

With a single stage all three play together, and that band can get any of 5 ratings.

Example 3
musicians=4, stages=3, max_rating=1 → 81

The rating is always 1, so only the stage assignments count: 3⁴ = 81.

Constraints
  • 1 ≤ musicians, stages, max_rating ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTasters and the Spoiled Cask HardRadio Show Without Quick Repeats HardParcel Run Orders HardA Fair Split of Colored Beads HardOther Orders for the Same Search Tree Hard
loading Python…
Input
musicians=2, stages=2, max_rating=2
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.