following images shows the problem statement
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
following images shows the problem statement
Name |
---|
Simple submask dp problem.
Let's count
dp[mask]
.mask
is an integer and it's i-th bit is gonna representate whether i-th skill is owned by Alice.dp[mask]
will be equal to mininimum cost of books we need to use to get skill setmask
.N <= 15
somask <= 2^N < 33000
.Let's say binary mask of the initial set of Alice's skills is
initMask
. Then at start we setdp[initMask] = 0
. All other dp values are gonna be equal to+INF
. To calculate the dp, we are going to iterate through all the booksi
and all the masksmask
. Then ifbookMask[i]
represents binary mask of i-th book, formula would be something like:dp[mask | bookMask[i]] = min(dp[mask | bookMask[i]], dp[mask] + bookCost[i])
, where|
is binaryOR
. After all the dp's are calculated the answer is the smallestdp[mask]
within allmask
s that contain the set of skills we need to get. If the answer is greater or equal to infinity, that means that Alice can't get such set of skills.The time complexity is smth like
O(2^N * M)
Got it!
Thanks