#include#include #include #include using namespace std;int a,b,shu[15],dp[15][10][2];inline int windy(int len,int last,bool limit,bool have){ if(len==0)return 1; if(!limit&&dp[len][last][have])return dp[len][last][have]; int maxi=limit?shu[len]:9,ans=0; for(int i=0;i<=maxi;i++){ if(have&&abs(i-last)<2)continue; ans+=windy(len-1,i,limit&&i==maxi,have||i); } if(!limit)dp[len][last][have]=ans; return ans;}inline int solve(int x){ memset(shu,0,sizeof(shu)); int tot=0; while(x){ shu[++tot]=x%10; x/=10; } return windy(tot,0,true,false);}int main(){ scanf("%d%d",&a,&b); printf("%d\n",solve(b)-solve(a-1));}
注意有绝对值