Hello All,
I am very new to the concept of dp with bitmasking. So, was going through some basic problems like this. My code's link is this: http://ideone.com/kerT7s . I have precalculated the distance between every restaurant location and the solitairs location. Then because we have the constraint of limited number of restaurants (n), my lowest number with n bits set is (1<<n)-1
. The next number will be the one with same number of set bits. Then corresponding to every set bit (which denotes the location of the restaurant), I am checking the distances of each solitiare if it lies within the permissible radius range.
But the above gives TLE. I have no clue why, someone please give some hint or point out the flaw. Will be really helpful. Thanks :)