I was trying to solve this problem on UVA : https://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3133 I have solved a similar problem with smaller constraint using dp+bitmask. Can anyone suggest some approach or link some similar problems.