思路:
首先,inedible tails 的个数最多为C(18+9,9)个(用隔板法),所以我们暴力出所有的 inedible tails,然后检查一下在[L, R]这段区间是否存在这个inedible tails
检查的时候用了和数位dp差不多的方法,设一个下界和上界,只要之前的既没有达到上界也没有达到下界,后面就可以随便填了,说明存在
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #define rs rt<<1|1, m+1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pii pair<int, int> #define piii pair<pii, int> #define mem(a, b) memset(a, b, sizeof(a)) #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout); //head int l[25], r[25], f[25], ans = 0, cnt = 0; bool check(int pos, bool Llimit, bool Rlimit) { if(!Llimit && !Rlimit) return true; if(pos == 0) return true; int down = Llimit ? l[pos] : 0; int up = Rlimit ? r[pos] : 9; for (int i = down; i <= up; i++) { if(f[i]) { f[i]--; bool flag = check(pos-1, Llimit&&i==l[pos], Rlimit&&i==r[pos]); f[i]++; if(flag) return true; } } return false; } void dfs(int pos, int res) { if(pos == 9) { f[pos] = res; if(check(cnt, 1, 1)) ans++; return ; } for (int i = 0; i <= res; i++) { f[pos] = i; dfs(pos+1, res - i); } } int solve(LL L, LL R) { cnt = 0; while(L) { l[++cnt] = L%10; L /= 10; } cnt = 0; while(R) { r[++cnt] = R%10; R /= 10; } ans = 0; dfs(0, cnt); return ans; } int main() { LL L, R; scanf("%lld %lld", &L, &R); printf("%d ", solve(L, R)); return 0; }