Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[ACM-ICPC] Top-down & Bottom-up

KuoE0
February 20, 2013

[ACM-ICPC] Top-down & Bottom-up

KuoE0

February 20, 2013
Tweet

More Decks by KuoE0

Other Decks in Programming

Transcript

  1. Fibonacci Sequence fib(5) fib(4) fib(3) fib(2) fib(1) fib(2) fib(1) fib(0)

    fib(0) fib(1) fib(2) fib(3) fib(1) 1 0 1 1 2 1 0 1 3
  2. Fibonacci Sequence fib(5) fib(4) fib(3) fib(2) fib(1) fib(2) fib(1) fib(0)

    fib(0) fib(1) fib(1) fib(2) fib(3) fib(0) fib(1) 1 0 1 1 2 1 0 1 3
  3. Fibonacci Sequence fib(5) fib(4) fib(3) fib(2) fib(1) fib(2) fib(1) fib(0)

    fib(0) fib(1) fib(1) fib(2) fib(3) fib(0) fib(1) 1 0 1 1 2 1 0 1 3 1 0 1
  4. Fibonacci Sequence fib(5) fib(4) fib(3) fib(2) fib(1) fib(2) fib(1) fib(0)

    fib(0) fib(1) fib(1) fib(2) fib(3) fib(0) fib(1) 1 0 1 1 2 1 0 1 3 1 0 1 1 2 5
  5. int fib( int x ) { if ( x <=

    0 ) return 0; if ( x == 1 ) return 1; return fib( x - 1 ) + fib( x - 2 ); } int main() { int ret = fib( 10 ); return 0; }
  6. int main() { int f0 = 0, f1 = 1,

    f2; for ( int i = 0; i < 10; ++i ) { f2 = f0 + f1; f0 = f1, f1 = f2; } return 0; }