[Math] Simple combinations – Party Lamps [IOI 98]

combinatorics

You are given N lamps and four switches. The first switch toggles all lamps, the second the even lamps, the third the odd lamps, and last switch toggles lamps $1, 4, 7, 10, \dots $

Given the number of lamps, N, the number of button presses made (up to $10,000$), and the state of some of the lamps (e.g., lamp $7$ is off), output all the possible states the lamps could be in.

Naively, for each button press, you have to try $4$ possibilities, for a total of $4^{10000}$ (about $10^{6020}$ ), which means there's no way you could do complete search (this particular algorithm would exploit recursion).

Noticing that the order of the button presses does not matter gets this number down to about $10000^4$ (about $10^{16}$ ), still too big to completely search (but certainly closer by a factor of over $10^{6000}$ ).

However, pressing a button twice is the same as pressing the button no times, so all you really have to check is pressing each button either 0 or 1 times. That's only $2^4 = 16$ possibilities, surely a number of iterations solvable within the time limit.

Above is a simple problem with a brief explanation of the solution. What I am
not able to conclude is the part where it says order doesn't matter and switches
solution from $4^{10000}$ to $10000^4$.
Any idea ?

Best Answer

If order doesn't matter then all that matters is how many times each switch is toggled. There are four switches; let's say the first one is toggled $a$ times, the second, $b$ times, the third, $c$ times, the fourth, $d$ times. Since the total amount of toggling is given as at most $10000$, we have $$a+b+c+d\le10000$$ So now consider $10004$ stones lying in a line on the ground, and paint $4$ of them blue. This leaves $10000$ unpainted stones in $5$ groups, corresponding to the numbers $a$, $b$, $c$, $d$, and $10000-(a+b+c+d)$. So, the number of solutions of the displayed inequality is $10004$-choose-$4$, which is very roughly $10000^4$. A somewhat less rough estimate would be $(1/24)(10000^4)$.

Related Question