getting tle @ http://www.spoj.com/problems/HELPBOB/

im using dp+bitmask for solving the problem http://www.spoj.com/problems/HELPBOB/ .
my complexity is O(N*2^N) which seems fine for n=15(max).but im getting tle.
please suggest what could be wrong with my code
here’s the link
http://ideone.com/KwQC2f

//