题意: 求l - r 之间满足偶数位全是d且奇数位不能出现d且是m的倍数的数的个数
题解:数位dp,之间套板子,注意有前导零的存在
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstring>
#include<stack>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<climits>
#define fors(i, a, b) for(int i = (a); i <= (b); ++i)
#define scanf1(a) scanf("%d",&a)
#define scanf2(a,b) scanf("%d%d",&a,&b)
#define scanf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define ll long long
#define readType int
using namespace std;
const int mx = 2100;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
inline readType read() {
char c = getchar(); readType x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
ll dp[mx][mx][2][2];
string b;
int m, d;
//当前的位置, 前面的值, 是否限制, 前导零, 是否有奇数个前导0
ll dfs(int pos, int sum, int limit, int lead, int even){
if(pos == (int)b.size())
return sum % m == 0;
if(!limit && dp[pos][sum][lead][even] != -1)
return dp[pos][sum][lead][even];
int up = limit ? b[pos] - '0' : 9;
ll ans = 0;
for(int i = 0; i <= up; i ++){
if(((pos - even) & 1) && i != d)
continue;
if(!((pos - even) & 1) && i == d)
continue;
if(lead && i == 0)
ans = (ans + dfs(pos + 1, (sum * 10 + i) % m, limit && (i == up), 1, even ^ 1)) % mod;
else
ans = (ans + dfs(pos + 1, (sum * 10 + i) % m, limit && (i == up), 0, even)) % mod;
}
if(!limit)
dp[pos][sum][lead][even] = ans;
return ans;
}
ll solve(string num){
b = num;
return dfs(0, 0, 1, 1, 0);
}
int check(string num){
int sum = 0;
for(int i = 0; i < (int)num.size(); i ++){
sum = (sum * 10 + num[i] - '0') % m;
if(i & 1){
if(num[i] != '0' + d) return 0;
}else{
if(num[i] == '0' + d) return 0;
}
}
return sum == 0;
}
int main2(){
memset(dp, -1, sizeof dp);
cin >> m >> d;
string a, b;
cin >> a >> b;
cout << (check(a) + solve(b) - solve(a) + mod) % mod << endl;
return 0;
}
int main(){
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _;//_ = read();
_ = 1;
while(_--)main2();return 0;
}