就搞不懂为什么我多预处理了几位就会炸 然后放mzoj上还非要预处理8位
真的要叫我去写dfs版的吗QAQ
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<cmath> #include<stack> #include<algorithm> using namespace std; #define ll long long #define rg register const int N=2000000000+5,pw=11,inf=0x3f3f3f3f,P=19650827; ll a,b,x,y; ll base[20],f[20][10]; //填了多少 当前 template <class t>void rd(t &x) { x=0;int w=0;char ch=0; while(!isdigit(ch)) w|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=w?-x:x; } void pre(){ for(int i=0;i<=9;++i) f[1][i]=(!(i==4)); for(int i=2;i<=8;++i) for(int j=0;j<=9;++j){ if(j==4) {f[i][j]=0;continue;} for(int k=0;k<=9;++k) if(!(k==4||j==6&&k==2)) f[i][j]+=f[i-1][k]; } } ll solve(ll xx){ ll p=0,num[20],sum=0; // for(p=0;p<=13;++p) if(base[p]>x) break; while(xx) num[++p]=xx%10,xx/=10; num[p+1]=0; /* for(int i=1;i<p;++i) for(int j=1;j<=9;++j) sum+=f[i][j]; for(int i=1;i<num[p];++i) sum+=f[p][i]; for(int i=p-1;i>0;--i){ for(int j=0;j<num[i];++j) if(!(j==2&&num[i+1]==6)) sum+=f[i][j]; if(num[i]==4||(num[i]==2&&num[i+1]==6)) break; }*/ for(int i=p;i>0;--i){ for(int j=0;j<num[i];++j) if(!(j==2&&num[i+1]==6)) sum+=f[i][j]; if(num[i]==4||(num[i]==2&&num[i+1]==6)) break; } return sum; } int main() { //freopen("in.txt","r",stdin); //freopen("nocows.out","w",stdout); pre(); /* for(int i=1;i<=9;++i){ printf(" "); for(int j=0;j<=9;++j) printf("%d ",f[i][j]); }*/ while(scanf("%lld%lld",&a,&b)==2&&a&&b){ printf("%lld ",solve(b+1)-solve(a)); } return 0; }