Test instructions
As the annual heavyweight figure in ACM history, Bin Ju has mastered the history of the most NB, the group giant fast to admire!! We define such a number, each of which is in pairs, but if the number exists in 0 then this is NB number, such as 11,122122,12035, of course, the need to eliminate those first is 0 of the number. Our goal is to calculate how many NB the bin giant has in a range!
Ideas:
Simple digital DP, you need to consider the number of occurrences of each number (0,1), whether there is a leading 0, whether it appears 0.
It is important to note that 0 is not a bin huge number.
#include "cstdlib" #include "Cstdio" #include "CString" #include "Cmath" #include "queue" #include "algorithm" #include " iostream "#include" map "#define LL long longusing namespace Std;ll dp[22][2025][2][2];int num[22];int Fun (int x) {for (int i=1;i<=9;i++) if (x& (1<<i)) return 0; return 1;} ll DFS (int site,int ok,int zero,int kx,int f) {if (site==0) {if (zero==0) return 0; if (KX) return 1; return fun (OK); } if (!f && dp[site][ok][zero][kx]!=-1) return DP[SITE][OK][ZERO][KX]; int len=f?num[site]:9; ll Ans=0; for (int i=0; i<=len; i++) {if (zero==0 && i==0) Ans+=dfs (Site-1,ok,0,0,f&&i==len); else if (KX) Ans+=dfs (Site-1,0,1,1,f&&i==len); else {if (i==0) Ans+=dfs (Site-1,0,1,1,f&&i==len); else {int Tep=ok; if (tep& (1<<i)) tep-= (1<<i); else tep|= (1<<i); Ans+=dfs (site-1,tep,1,0,f&&i==len); }}} if (!f) Dp[site][ok][zero][kx]=ans; return ans;} ll solve (ll x) {if (x<0) return 0; int cnt=0; while (x) {num[++cnt]=x%10; x/=10; } return Dfs (cnt,0,0,0,1);} int main () {int t; Memset (Dp,-1,sizeof (DP)); cin>>t; while (t--) {ll A, B; scanf ("%lld%lld", &a,&b); if (a>b) swap (A, b); printf ("%lld\n", Solve (b)-solve (A-1)); } return 0;}
[Digital DP] Kuangbinoj 1012 bin giant Number