how to solve a question like this http://www.spoj.com/problems/GNY07H/

I want a dp+bitmasking solution and I want to ask how to attempt such questions.