Test instructions: For [A, a] between, any adjacent two-digit difference is greater than or equal to 2 of the number of the f[i][j]=: set the number of the legal number of the first I-bit j, there is obviously f[i][j]=f[i-1][k],|k-j|≥2. As for the statistical answer, as long as we can ask for the number of legal numbers between 1-u, the obvious answer is Ans[b]-ans[a-1]. As for Ans[i] ... Because Ans[10^t] is better to ask, so one statistic is good.
#include <cmath>#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespacestd;#definell Long LongConst intmaxn=Ten; ll A,b,f[maxn+2][maxn+2];ll Calc (ll x) {intn=0, G[MAXN]; ll Ans=0; if(!x)return 0; Memset (g,0,sizeof(g)); while(x) g[++n]=x%Ten, x/=Ten; for(intI=1; i<g[n];i++) ans+=F[n][i]; for(inti=n-1; i;i--) for(intj=1; j<=9; j + +) ans+=F[i][j]; for(inti=n-1; i;i--){ for(intj=0; j<g[i];j++) if(ABS (g[i+1]-J) >=2) ans+=F[i][j]; if(ABS (g[i+1]-g[i]) <2) Break; } returnAns;}intMain () {CIN>> A >>B; for(intI=0; i<=9; i++) f[1][i]=1; for(intI=2; i<=maxn;i++) for(intj=0; j<=9; j + +) for(intk=0; k<=9; k++) if(ABS (J-K) >=2) f[i][j]+=f[i-1][k]; cout<< Calc (b +1)-calc (A) <<Endl; return 0;}
View Code
BZOJ1026 SCOI2009 Windy number general DP