Please read the new rule regarding the restriction on the use of AI tools. ×

LIFE_GOES_ON's blog

By LIFE_GOES_ON, history, 4 years ago, In English

In this 294C - Shaass and Lights I do not understand clearly what to do next. I have figured out that if there are n off lights between two on lights , number of ways to turn them on is 2^(n-1) . And for consecutive off lights having only one adjacent on light can only be turned on in one way. In the third sample test case lights from 5 to 7 can be turned on in 2^2 ways . And lights from 1 to 3 can be turned on in 1 way. Also, lights from 9 to 11 can be turned on in 1 way. So answer will be X * 1 * 4 * 1 . Now how to find this "X" ??

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 4   Vote: I like it +1 Vote: I do not like it

Your initial deductions are all correct. Now, what does it mean for two ways of switching on the lights to be different? Normally the problem statement would say what exactly this means, but we can guess that it just means that if you list out all the lights you turn on as sequences, then there is some index $$$i$$$ such that the $$$i$$$th light you turn on in the first sequence is different from the second sequence. So, you seem to know how to calculate the answer when there is only one contiguous segment of "off" lights. The next thing you should try to do is figure out how to calculate the answer when there are two contiguous segments of "off" lights. For example, the test case $$$n=3, m=1$$$ with light 2 turned on. You'll notice there are two ways to turn the lights on, [1, 3] and [3, 1]. Now, what if we take the case $$$n=5, m=1$$$ with the light 3 turned on? Now, we have 6 ways: [2, 1, 4, 5], [2, 4, 1, 5], [2, 4, 5, 1], [4, 2, 1, 5], [4, 2, 5, 1], [4, 5, 2, 1]. You'll notice that we are basically figuring out all the ways of interleaving the two segments [2, 1] and [4, 5]. There are $$$\binom{4}{2}$$$ ways of doing this. For more segments, we simply figure it out using multinomial coefficients. In your example, you'll notice that X is given by the multinomial coefficient $$$\dfrac{9!}{3!3!3!}$$$.