Could somebody explain the approach for Problem B, 157-div1 Little Elephant and Elections, especially the DP approach that is mentioned in the editorials (mainly how to write the state dp ( state[position][less][count] ))
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Could somebody explain the approach for Problem B, 157-div1 Little Elephant and Elections, especially the DP approach that is mentioned in the editorials (mainly how to write the state dp ( state[position][less][count] ))
Название |
---|
we need: how many numbers is less than or equal m and contains exactly [count] lucky digits. if state is DP[position][less][count] so cnt[k] = DP[0][false][k] were k is number of lucky digits.
we start from left to right and use digits that we can.
for example let m is 53237
we start from left:
if we choose [0 to 4] for first digit (leftmost digit), for next digits we are free to use all digits [0-9] because we are sure that all next numbers will be less than m. so we set [less] flag true. and answer is:
DP[position][less][count] = Sigma{ DP[position + 1][true][count — (if we use lucky digit ? 1 : 0)] } for all digits we can use
but if we choose 5 for first digit, for next digit we can only use [0-3] so [less] flag remains false. so answer is:
DP[position][less][count] = Sigma{ DP[position + 1][false][count — (if we use lucky digit ? 1 : 0)] } for all digits we can use
at the end if [position] == |m|:
DP[position][less][count] = (count == 0 ? 1 : 0)
sorry for poor English!
Thank you, Today is my lucky day getting reply's on all of my posts.