In case of further doubt’s you can ask again. 
Tester’s solution link isn’t working
Nor editorialist’s…
check these:
tester : csfZJZ - Online C++0x Compiler & Debugging Tool - Ideone.com
editorialist : k6PWH8 - Online C++0x Compiler & Debugging Tool - Ideone.com
Thanks for all this support…
@likecs
By the way, i am learning to use dp+bitmask to account for permutations… (which is an entirely new territory to me).
Anyway, Thanks
@likecs can you please provide a link from where i can understand that it’s covering all the possible permutations ! As far i understand i think that i land on (5^n * 2^n) solution