Editorial for COCI '08 Contest 5 #5 Tresnja
Submitting an official solution before solving the problem yourself is a bannable offence.
Let consider all numbers in the interval . The function calculates the total contribution towards the result of digits yet to be placed to the right of the given prefix.
To calculate , we add a group of any digit other than the last one in prefix. For example, suppose and . considers the numbers through . If we decide to append the group to the number, the contribution of this recursive branch is .
It may seem that it takes too many recursive calls to calculate the result. However, many of these yield the same result for different prefixes, more precisely when the entire interval considered is contained inside . For these cases, we can memoize the result (it depends only on ). There are only recursive calls in which we branch without memoization.
Comments