Interesting problem on dynamic programming from atcoder. Given a string in the format "(|?)+" find how many number can be formed such that the reminder of the division of each of this numbers by 13 gives exactly 5.
So lets define function dp[x][y]
to be count of such numbers for prefix of length x
and reminder y
.
For example, for 1?2
dp[2][5]
will mean the count of such numbers for substring 1?
and the reminder 5.
The interesting part is the transition. It uses implicit difinition.
for (all prevReminder)
dp[i+1][ (prevReminder * 10 + curDigit)%13 ] += dp[i][prevReminder]