Title Address: HDU 4389
The first time you encounter a need to enumerate and then the digits DP.
The sum of the numbers is enumerated first, that is, 1~81, then the sum of the enumerated members in the digital DP process is the same as the number of enumerations, only the same counts.
DP[I][J][K][H] denotes the number of digits of the current number of members, and for J, the number of members enumerated, and K, the current numbers of K modulo H.
The code is as follows:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace STD;#define LL __int64#define PI ACOs ( -1.0)Const intMod=1e9+7;Const intinf=0x3f3f3f3f;Const Doubleeqs=1e-9;Const intmaxn=200000+Ten;intdp[ One][ the][ the][ the], dig[ One];intDfsintCntintSumintModsintResintMaxd) {if(cnt==-1)returnsum==mods&&res==0;if(Sum>mods)return 0;if(maxd&&dp[cnt][sum][mods][res]!=-1)returnDp[cnt][sum][mods][res];intI, R=maxd?9:d ig[cnt], ans=0; for(i=0; i<=r;i++) {Ans+=dfs (cnt-1, Sum+i,mods, (res*Ten+i)%mods,maxd| | I<R); }if(Maxd) Dp[cnt][sum][mods][res]=ans;returnAns;}intCal (intx) {intI, cnt=0, ans=0; while(x) {dig[cnt++]=x%Ten; X/=Ten; } for(i=1; i<=Bayi; i++) {Ans+=dfs (cnt-1,0I0,0); }returnAns;}intMain () {intT, L, R, case=0;memset(dp,-1,sizeof(DP));scanf("%d", &t); while(t--) {scanf("%d%d", &l,&r);printf("Case%d:%d\n", ++case,cal (R)-cal (l1)); }return 0;}
HDU 4389 x mod f (x) (digital DP)