I came across this problem on Uva online judge from NWERC regional semilive 2010
I have thought about a method where map<vector<pair<int,int>>,int> dp stores the best possible score Jan for the state vector<pair<int,int>>.... but i dont know how to proceed further and feel that the method is inefficient...
please help......
There is at most n<=1000 goodies and at most t <= 100 test cases. I think sraightforward solution will pass all test cases.