Digital DP beginners,CodeIt is the same on the Internet, with a high degree of similarity of digital DP code
A good problem solving http://www.cnblogs.com/luyi0619/archive/2011/04/29/2033117.html
# Include <iostream> # include <cstring> # include <cstdio> # define llong long longusing namespace STD; llong DP [20] [3]; int digit [20]; int main () {int I; int t; memset (DP, 0, sizeof (DP); DP [0] [0] = 1; for (I = 1; I <20; I ++) {DP [I] [0] = DP [I-1] [0] * 10-dp [I-1] [1]; DP [I] [1] = DP [I-1] [0]; DP [I] [2] = DP [I-1] [2] * 10 + dp [I-1] [1];} scanf ("% d", & T ); while (t --) {int Len = 0, last = 0; llong ans = 0; unsigned llong n = 0; scanf ("% i64d", & N ); N ++; // someone asks the purpose of this step. Run memset (digit, 0, sizeof (DIGIT); While (n) {digit [++ Len] = n % 10; n/= 10;} bool flag = 0; for (I = Len; I> = 1; I --) {ans + = DP [I-1] [2] * digit [I]; If (FLAG) ans + = DP [I-1] [0] * digit [I]; If (! Flag & digit [I]> 4) ans + = DP [I-1] [1]; If (last = 4 & digit [I] = 9) flag = 1; last = digit [I];} printf ("% i64d \ n", ANS);} return 0 ;}