Black_hat123's blog

By Black_hat123, history, 5 years ago, In English

Can anybody please tell how to solve This problem..

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

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Notice that the problem is asking you to find the solution to the following problem:

f(N) = f(N-a) + f(N-b), where f(0) = 1

Since N can be quite large, you cannot simply solve bottom up, as this would be O(N). The correct approach is to utilize matrix exponentiation to solve recurrence relations. I recommend a google search for doing this with a simple recurrence relation to start, fibonacci. After that, you will see that this is easily solved in a similar way.