Topic links
Give two numbers m, d. Two number A, B. A, b length is less than 2000, the length is equal. For the number of X, X%m==0, and from high to low, the number of odd digits is not equal to D, the number of even numbers is all equal to D, and the number of such numbers is obtained.
Digital DP, usually from back to front DFS, but this problem because there is a second condition, so should be from the go after DFS, the specific DFS process to see the code.
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };intm, D, Len;Chars[2005];ll dp[2005][2005];ll DFS (intPosintMdintFP) { if(pos = = len+1) { returnMD = =0; } if(~dp[pos][md]&&!FP) { returnDP[POS][MD]; } inted = fp?s[pos]-'0':9; LL ret=0; for(inti =0; i<=ed; i++) { if(pos%2&&i==d)Continue; if(pos%2==0&&i!=d)Continue; RET= (ret + DFS (pos+1, (md*Ten+i)%m, fp&&i = = ed))%MoD; } returnFP?RET:DP[POS][MD] =ret;}intMain () {MEM1 (DP); CIN>>m>>D; scanf ("%s", s+1); Len= strlen (s+1); intTMP =0, flag =0; for(inti =1; i<=len; i++) {tmp= tmp*Ten+s[i]-'0'; TMP%=m; if(i%2&&s[i]-'0'==d) Flag=1; if(i%2==0&&s[i]-'0'!=d) Flag=1; } if(tmp!=0) Flag=1; ll Ans1= DFS (1,0,1); if(!flag) ans1--; scanf ("%s", s+1); ll Ans2= DFS (1,0,1); cout<< (ans2-ans1+mod)%MoD; return 0;}
Codeforces 628D. Magic Numbers Digital DP