dp / bit-masking / dp with profile / matrix exponentiation
How to approach this problem http://www.spoj.com/problems/AIRLINES/