Rabu, 28 Desember 2016

UVA 900 - Brick Wall Patterns Solution

Problem Statement: Brick Wall Patterns

Explanation

There's two way to assembly a wall of length n.

  • Put one brick in vertical position which gives us f(n-2) different patterns.
  • Put two horizontal brick on top of another which gives us f(n-1) different patterns.
Base case f(1) = 1 and f(2) = 2.

Optimization

Before doing the iteration check whether the answer has been found or not.

Source Code

Tidak ada komentar:

Posting Komentar