following images shows the problem statement
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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