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

Автор orchidmajumder, 13 лет назад, По-английски

Hi,

I was trying to solve this problem of finding no of possible ways of changing a value n.

http://www.spoj.com/problems/TPC07/

TJU judge link:

http://acm.tju.edu.cn/toj/showp2817.html

now this problem has a constraint of n<=10^9.so,I can't declare an array of that size and run a dp approach.Also,I think this problem will require BigInteger support by seeing the answer for the second test case.

So,any help on how to solve it using C/C++ would be much appreciated.

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

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

In DP, we must use this formula: F(i) = F(i-1) + F(i-5) + F(i-10) + F(i-25) + F(i-50)

As you can see, it is a linear function, so we can find F(n) faster than O(N) using matrix multiplications.

You can google "Fast k-th fibonacci algorithm", it can help you understand how to find F(N) for any linear function in O(logN*k^3).

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

You can find solution in "Concrete Mathematics", chapter 7.