9 - Random Grouping
CodeChefOpen on judge ↗
There are $N$ students numbered $1, 2, \ldots, N$. Their teacher wants to group them. The teacher is a fan of randomness and uses the following : Let $g$ denote the current number of groups. First the teacher makes one group containing the student $1$. So, initially $g = 1$. Now, for each student $i$ from $2$ to $N$ in this order: - With probability $1 / (g + 1)$, he creates a new group containi
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.
Sign in to chat with the tutor and save your progress.
Sign in to start