title: Stacking Tiles (Hard algorithm)
body: <p>This is a question from a code competition, I am finding it unbelievably difficult to come up with any working algorithm to solve it. So I'm not really looking for the code but rather a step by step algorithm on how to solve it.</p>
  
  <blockquote>
    <h3>Stacking Tiles</h3>
    
    <p>Stacking tiles against the wall is one of Bongani's favourite pasttimes. His tiles all have the same thickness, but vary
    in width and height. Bongani is given N tiles and has to use them in
    the sequence given according to a set of rules. He can place a tile on
    top of another only if it is narrower than the previously stacked
    tile. Bongani is allowed to rotate the tiles by 90 degrees so that
    width becomes height and height becomes width. He is also allowed to
    discard a tile altogether. Given a list of tiles, help Bongani find
    the highest stack he can build The example specifies tiles (3, 3),
    (12, 5), (5, 8), (6, 10). To get the highest stack Bongani ignores the
    first tile (3, 3) as it is smaller than the next tile. He uses the
    next tile (12, 5) with 12 as the width and 5 as the height. He uses
    the next two tiles with 8 as the width and 5 as the height followed by
    6 as the width and 10 as the height.</p>
  </blockquote>
  
  <p>The only thing I can possibly think of is getting every possible valid permutation of tiles and find the highest permutation. 
  The exact question can be found here <a href="http://www.olympiad.org.za/olympiad/wp-content/uploads/2013/01/2011PO-_R2_-Questions-0421.pdf" rel="nofollow">http://www.olympiad.org.za/olympiad/wp-content/uploads/2013/01/2011PO-<em>R2</em>-Questions-0421.pdf</a> (Question 5)</p>