题意:
题意比较难读:首先对于一个串来说, 如果他是d-串, 那么他的第偶数个字符都是是d,第奇数个字符都不是d。
然后求[L, R]里面的多少个数是d-串,且是m的倍数。
题解:
数位dp。
dp[x][y]代表的是余数为x, 然后剩下的长度是y的情况的方案数是多少。
代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e3 + ;
int dp[N][N];
/// left length
char s[N];
int m, d;
/// length, yu, lim
int dfs(int len, int yu, int lim, int g){
if(!lim && dp[yu][len] != -) return dp[yu][len];
if(len == ){
return !yu;
}
int up = ;
if(lim) up = s[len] - '';
LL tmp = ;
for(int i = ; i <= up; ++i){
if(g){
if(i != d) continue;
}
else {
if(i == d) continue;
}
tmp += dfs(len-, (yu*+i)%m, lim && (i==up), g^);
}
tmp %= mod;
if(!lim) dp[yu][len] = tmp;
return tmp;
}
bool check(int len){
int yu = , g = ;
for(int i = len; i >= ; --i){
if(g && s[i] != '' + d) return false;
if(!g && s[i] == '' + d) return false;
yu = (yu * + s[i] - '') % m;
g ^= ;
}
return yu == ;
}
int main(){
memset(dp, -, sizeof(dp));
scanf("%d%d", &m, &d);
scanf("%s", s+);
int len1 = strlen(s+);
reverse(s+, s++len1);
LL ans = check(len1) - dfs(len1, , , );
scanf("%s", s+);
len1 = strlen(s+);
reverse(s+, s++len1);
ans += mod + dfs(len1, , , );
ans %= mod;
cout << ans << endl;
return ;
}