Dynamic programming with bit masking?

How to improve dynamic programming with bit masking?