Recently, I have been practicing the digital dp. This is still a problem of wang. This is a basic question. I have nothing to say. I have attached the code.
# Include <stdio. h> # include <string. h> # define LL unsigned long longLL dp [3] [30]; LL a [30]; void init () {int I, j, k; dp [0] [0] = 1; for (I = 1; I <22; I ++) {dp [0] [I] = dp [0] [I-1] * 10-dp [1] [I-1]; dp [1] [I] = dp [0] [I-1]; dp [2] [I] = dp [2] [I-1] * 10 + dp [1] [I-1];} LL solve (LL n) {int I, j, k, len; for (I = 1; n; I ++) {a [I] = n % 10; n/= 10;} len = I; a [len] = 0; LL ans = 0, flag = 0; for (I = len-1; I> 0; I --) {ans + = a [I] * dp [2] [I-1]; if (flag) ans + = a [I] * d P [0] [I-1]; else {if (a [I]> 4) ans + = dp [1] [I-1]; // here I started to write if (a [I + 1]> 4) ans + = dp [0] [I-1], wrong once ~ } If (a [I + 1] = 4 & a [I] = 9) flag = 1;} return ans;} int main () {init (); int I, j, k, t; LL n; scanf ("% d", & t); while (t --) {scanf ("% I64u", & n ); printf ("% I64u \ n", solve (n + 1);} return 0 ;}