ll dfs(int x, int st, int op, vector<int> &dim){ // op = 0 means <, op = 1 means == // st = 10 when it is leading zero if (x == -1) return1; ll &ret = f[x][st][op]; if (ret != -1) return ret; ret = 0;
int m = op ? dim[x] : 9; for(int i = 0; i <= m; i++) if (abs(st - i) >= 2 || st == 10){ ret += dfs(x - 1, (st == 10 && i == 0) ? 10 : i, op & (i == m), dim); } return ret; }
#include<bits/stdc++.h> usingnamespacestd; #define rep(i,from,to) for(register int i=from;i<=to;++i) #define For(i,to) for(register int i=0;i<(int)to;++i) typedeflonglong ll;
constlonglong M = 1000000007;
vector<int> l, r; ll f[1024][11][11][2];
inlinevoidread(vector<int> &res){ res.clear(); char c = getchar(); while(c < '0' || c > '9') c = getchar(); while(c >= '0' && c <= '9') { res.push_back(c - '0'); c = getchar(); } }
ll dp(int x, int st1, int st2, int op, vector<int> &dim){ if(x == (int)dim.size()) return1; ll &ret = f[x][st1][st2][op]; if (ret != -1) return ret; ret = 0;
int m = op ? dim[x] : 9;
for(int i = 0; i <= m; i++) if (st1 != i && st2 != i){ if (st2 == 10 && i == 0) { ret += dp(x + 1, 10, 10, op & (i == m), dim); } else { ret += dp(x + 1, st2, i, op & (i == m), dim); } ret %= M; } return ret; }
ll solve(vector<int> &dim){ memset(f, -1, sizeof(f)); ll res = dp(0, 10, 10, 1, dim); // res is count of all the un-meng numbers k s.t. 0 <= k <= n, n represented by dim ll s = 0; For(i, dim.size()) { int u = dim[i]; s = (s * 10) % M; s = (s + u) % M; } s = s - res + 1; s %= M; s += M; s %= M; return s; }
booljudge(vector<int> &dim){ for(int i = 0, s = dim.size(); i < s - 2; ++i) { if (dim[i] == dim[i + 2] || dim[i] == dim[i + 1] || dim[i + 1] == dim[i + 2]) returntrue; } returnfalse; }
intmain(){ #ifdef D freopen("3413.in", "r", stdin); #endif read(l); read(r); ll ans = solve(r) - solve(l) + judge(l); ans %= M; ans += M; ans %= M; cout << ans << "\n"; return0; }
This article was last updated on days ago, and the information described in the article may have changed.