X mod f(x) [HDU 4389] 数位DP模板
http://acm.hdu.edu.cn/showproblem.php?pid=4389
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
const int MM = 1111; typedef __int64 int64; #define debug puts("wrong") int N,M; int num[MM], cnt; int dp[10][82][82][82]; int dfs(int le,int sum,int mod,int r,bool less) { //less前一位是否取到最大e=less?num[le]:9 if(sum>mod) return 0; if(le==-1) {return sum==mod && r==0;} //边界条件,特定题目 if(!less && dp[le][sum][mod][r]!=-1) return dp[le][sum][mod][r]; int res=0,d, e=less?num[le]:9; for(d=0;d<=e;d++) { res+=dfs(le-1,sum+d,mod,(r*10+d)%mod,less&&d==e); } if(!less) dp[le][sum][mod][r]=res; return res; } int cal(int x) { int ans=0, mod, i; for(cnt=0 ;x; num[cnt++]=x%10,x/=10); for(mod=1;mod<=81;mod++) ans+=dfs(cnt-1,0,mod,0,true); return ans; } void solve() { int i,j,k,L,R; scanf("%d%d",&L,&R); printcase(); printf("%d\n",cal(R)-cal(L-1)); } int main() { int ca; scanf("%d",&ca); memset(dp,-1,sizeof(dp)); while(ca--) solve(); return 0; }