前言
在前一节链接里,我们讨论了数位dp的基础应用,从数位dp的简单状态刻画状态方程的给出,以及之后给出了较为统一的记忆化模板来解决大多数问题,在这一节里首先给出一个较复杂的状态方程求解问题,剩下3个用记忆化解决的问题来加深印象。
The Counting Problem
POJ 2282 题目链接
Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the list will be
1024 1025 1026 1027 1028 1029 1030 1031 1032
there are ten 0’s in the list, ten 1’s, seven 2’s, three 3’s, and etc.
【题目大意】求出给定区间内0~9每个数出现的次数
【题目思路】定义dp[i][j][k]为 以j开头含有i位数字 其中出现数字k的个数
状态转移方程:若j=k,(即第一位数字为出现的数字), dp[i][j][k]=10i−1 ,表示以j开头后面任意;
dp[i][j][k]=∑9