Блог пользователя dush1729

Автор dush1729, история, 11 лет назад, По-английски

Problem link

Why is the answer 2 ^ ( n — 1 ) ?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Suppose the correct answer for f(n) = k and we want to find out f(n+1)

One could either place the highest number i.e. (n+1) either towards the rightmost end in the permutation or towards the leftmost end to satisfy constraints "maximum element between the indices [i..j] is either present at index i, or at index j" to satisfy for [1...n]. The other inner constraints would automatically be satisfied as we know f(n) is true. So there are 2 possible choices. f(n+1) = 2*f(n)

Now the base case n = 1. There is only 1 choice so f(1) = 1. Kind of Mathematical Induction Proof :P

So a recurrence relation f(n) = 2*f(n-1) when n > 1. Solving this recurrence f(n) = 2**n-1