Hdu 2089 is not 62 (Digital dp)
Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 2089
Idea: Use variables to record the number of Geely, and the number of Geely with the highest digit of 2 is not the number of Geely...
Code:
# Include
# Include
# Includeusing namespace std; int dp [10] [3]; // dp [I] [j], I indicates the number of digits, and j indicates the status
// Dp [I] [0], indicating that there is no unlucky number
// Dp [I] [1], indicating that there is no unlucky number and the highest digit is 2
// Dp [I] [2], indicating that an unlucky number exists
void Init()
{Memset (dp, 0, sizeof (dp); int I; dp [0] [0] = 1; for (I = 1; I <= 6; I ++) {dp [I] [0] = dp [I-1] [0] * 9-dp [I-1] [1]; // should have been multiplied by 10, but if 4 does not meet the conditions, multiply it by 9 and set the I-th to 6, the I-1 bit is 2 minus dp [I] [1] = dp [I-1] [0]; // start with 2 dp [I] [2] = dp [I-1] [2] * 10 + dp [I-1] [0] + dp [I-1] [1]; }} int solve (int n) {int I, len = 0, tem = n, ans, flag, a [10]; while (n) {a [++ len] = n % 10; n/= 10;} a [len + 1] = ans = 0; flag = 0; for (I = len; i> 0; I --) {ans + = dp [I-1] [2] * a [I]; if (flag) // when to a certain, already Are you sure it's not auspicious count {ans + = dp [I-1] [0] * a [I];} if (! Flag & a [I]> 4) {ans + = dp [I-1] [0];} if (! Flag & a [I + 1] = 6 & a [I]> 2) {ans + = dp [I] [1];} if (! Flag & a [I]> 6) {ans + = dp [I-1] [1];} if (a [I] = 4 | (a [I + 1] = 6 & a [I] = 2) {flag = 1 ;}} return tem-ans; // because the question requires the number of auspicious numbers, use the total number minus the number of non-auspicious numbers} int main () {int l, r; Init (); while (scanf ("% d", & l, & r) = 2) {if (l = 0 & r = 0) break; printf ("% d \ n", solve (r + 1)-solve (l); // because in solv () the function does not determine whether n is a Geely number. Therefore, we need to add 1 .} return 0 ;}