following images shows the problem statement
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | 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 | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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