← All problemsSign in

Counting Problem

CodeChefRating 2819Open on judge ↗

There are $N$ bags. Each bag contains $M$ balls numbered $1$ to $M$. Note that for every $i \in [1, M]$, there is exactly one ball with number $i$ in each bag. You took exactly one ball from each bag and arranged the balls in a row, with the $i$-th ball being from the $i$-th bag. Given a number $K$, count the number of arrangements such that: - There exists **at least** one ball numbered $K$ in

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start