Can someone please help me in solving D. of today's Atcoder beginner contest.
Editorials are not available in English and I am not able to approach this problem on my own.
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
Can someone please help me in solving D. of today's Atcoder beginner contest.
Editorials are not available in English and I am not able to approach this problem on my own.
Название |
---|
Here is my solution which is different from the official one. (My English is very poor, sorry)
Let
dp[i][j]
be the maximum number of digits of the answer, which is made with i matches and has j as the first(highest) digit.Thus we can easily get
dp[i + c[A[k]]][A[k]] = max(dp[i + c[A[k]]][A[k]], dp[i][A[j]] + 1)
, whereA[i]
means the i-th available digit andc[i]
means the cost of digit i.Finally, we can greedily output the answer. For i, the number of matches left now, consider a best j with max{f[i][j]}. If there exists some js with the same value, just use the maximum j. This strategy is correct, because when we compare two numbers, we first consider their total length, and then from high digits to low digits.
Here is my solution for a better understanding :)
how u store so large numbers and why u dont use recursive approach
You don't need to actually store the whole number, instead, you split it in into digits.
As for the way to achieve the algorithm, you can use recursive approach if you like. It doesn't matter.
The main insight for these type of questions where you must output a big integer that is maximum is to first maximize length. If there are multiple answers of the same length, break ties by choosing the lexicographically larger number.
I maintained two arrays. F(i) represents the maximum length possible with exact cost i A(i, d) represents the length of the number with total cost i and last digit d.
Here is my code and explanation.