容易发现一个数是萌数当且仅当存在两个相同的数且下标差小于等于 $2$,于是数位 $dp$。
#include <bits/stdc++.h>
using namespace std;
const int N = 1010, mod = 1e9 + 7;
int a[N], f[N][20][20];
void init() {
for (int j = 0; j <= 10; j ++ )
for (int k = 0; k <= 10; k ++ )
if (j != k || (j == 10 && k == 10))
f[0][j][k] = 1;
for (int i = 1; i <= 1000; i ++ )
for (int j = 0; j <= 10; j ++ )
for (int k = 0; k <= 10; k ++ )
for (int p = 0; p <= 9; p ++ )
if ((j != k || (j == 10 && k == 10)) && j != p && p != k)
f[i][j][k] = (f[i][j][k] + f[i - 1][k][p]) % mod;
}
int solve(string s) {
if (s == "0") return 0;
int n = 0;
for (int i = s.size() - 1; i >= 0; i -- ) a[++ n] = s[i] - '0';
while (a[n] == 0 && n > 1) n -- ;
int lla = 10, la = 10, ans = 0;
for (int i = n; i >= 1; i -- ) {
int x = a[i];
for (int j = (i == n) ? 1 : 0; j < x; j ++ ) {
if (lla == j && la != j) continue;
ans = (ans + f[i - 1][la][j]) % mod;// cout << i - 1 << ' ' << la << ' ' << j << ' ' << f[i - 1][la][j] << endl;
}
if (i == n) {
for (int j = 0; j < n - 1; j ++ )
for (int k = 1; k <= 9; k ++ )
ans = (ans + f[j][10][k]) % mod;// cout << j << ' ' << 10 << ' ' << k << ' ' << f[j][10][k]<<endl;
}
if (x == la || x == lla) break;
lla = la, la = x;
if (i == 1) ans = (ans + 1) % mod;
}
return ans;
}
int MOD(string s) {
int n = 0;
for (int i = s.size() - 1; i >= 0; i -- ) a[++ n] = s[i] - '0';
while (a[n] == 0 && n > 1) n -- ;
int rest = 0;
for (int i = n; i >= 1; i -- )
rest = (rest * 10ll + a[i]) % mod;
return rest;
}
int main() {
init();
string l, r;
cin >> l >> r;
int pos = l.size() - 1;
while (l[pos] == '0') l[pos] = '9', pos -- ;
l[pos] -- ;
printf("%d\n",((MOD(r) + mod - MOD(l)) % mod + mod - (solve(r) + mod - solve(l)) % mod) % mod);
return 0;
}