Question: Ask 0~9 how many times these 10 numbers appear in [L,r].
IDEA: Digital DP. Previously just heard, and did not write, wrote to find a good upset AH.
Preprocessing an array, F[i][j][k] represents the length of I, starting with J, the number of times that the numbers K appears.
For a number kxxxxxx, we deal with 1~999999 first, and then we deal with 1000000~KXXXXXX
The front is very regular, you can directly call the F array to solve.
For things that are not very regular at the back, bitwise processing. In a word, I don't know what to say or do.
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;long long F[15][10][10],power[15];long long a[10],b[10];void work (long long X,long long arr[]) {Long Long temp = X;int len = 0;static int Digit[15];memset (digit,0,sizeof (digit)), while (x) digit[++len] = x% 10,x/= 10;x = temp;for (int i = 1; i < Len; ++i) for (int j = 1; J <= 9, ++j) for (int k = 0; k <= 9; ++k) arr[k] + = f[i][j][k];for (int i = len; i; i) {for (int j = 0; J < Digit[i]; ++J) {if (!j && i = = len) continue;for (int k = 0; k <= 9; ++k) arr[k] + = F[i][j][k];} Arr[digit[i]] + = x% power[i] + 1;}} int main () {power[1] = 1;for (int i = 2; I <=; ++i) power[i] = power[i-1] * 10;for (int i = 0; I <= 9; ++i) f[1][i][ I] = 1;for (int i = 2; I <=; ++i) for (int j = 0, J <= 9; ++j) for (int k = 0, K <= 9; ++k) {for (int z = 0; z <= 9; ++Z) f[i][k][z] + = F[i-1][j][z];f[i][k][k] + + power[i-1];} Long Long l,r;scanf ("%lld%lld", &l,&r); Work(R,a), work (l-1,b); for (int i = 0; I <= 9; ++i) printf ("%lld%c", A[i]-b[i], "\ n" [i = = 9]); return 0;}
Bzoj 1833 Zjoi count number of digits DP