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.

Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years.
×

Before contest

Codeforces Round #625 (Div. 1, based on Technocup 2020 Final Round)

26:30:42

Register now »

Codeforces Round #625 (Div. 1, based on Technocup 2020 Final Round)

26:30:42

Register now »

*has extra registration

Before contest

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)

26:30:42

Register now »

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)

26:30:42

Register now »

*has extra registration

# | User | Rating |
---|---|---|

1 | MiFaFaOvO | 3681 |

2 | tourist | 3496 |

3 | apiadu | 3438 |

4 | TLE | 3356 |

5 | LHiC | 3339 |

6 | mnbvmar | 3281 |

7 | 300iq | 3267 |

8 | Radewoosh | 3242 |

9 | yosupo | 3233 |

10 | 1919810 | 3203 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 190 |

2 | antontrygubO_o | 186 |

3 | tourist | 182 |

4 | Radewoosh | 168 |

5 | vovuh | 167 |

6 | pikmike | 165 |

7 | ko_osaga | 161 |

7 | Um_nik | 161 |

9 | rng_58 | 156 |

10 | Petr | 154 |

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.

↑

↓

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/29/2020 13:34:18 (e1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

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 withimatches and hasjas 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)`

, where`A[i]`

means thei-th available digit and`c[i]`

means the cost of digiti.Finally, we can greedily output the answer. For

i, the number of matches left now, consider a bestjwithmax{f[i][j]}. If there exists somejs with the same value, just use the maximumj. 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 :)

Thanks, I got it. And, your English is good. :-)

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.