13sabernow's blog

By 13sabernow, 12 years ago, In English

I got confused in this problem from LightOJ http://lightoj.com/volume_showproblem.php?problem=1011

As i am newbie in DP so i want some help in solving this problem using bitmask . Please explain me the steps so that i can use the technique in future . I cant understand how the calculations are done using DP and bitmasks .

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
12 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

You can solve this problem following this steps: 1. What will be state? It can be d[i][mask], how many couples and which women are free. 2. Transitions. If j — th woman is free, we can marry her to i — th man. So we are building new pair. 3. Where is answer? Answer will be in d[n][FULL_MASK].

Also you can write this dynamic by using one parameter. Logically, if j — th woman is not free, it means that she has a pair. So instead first parameter we can use number of ones in mask.

Hope you will get AC.

If you want I can give you code.