数位DP
cxlove基础数位DP第三题
= =预处理是个很有用的东西!然后就是分类讨论!
/**************************************************************
Problem: 1026
User: Tunix
Language: C++
Result: Accepted
Time:0 ms
Memory:1272 kb
****************************************************************/ //BZOJ 1026
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') sign=-; ch=getchar();}
while(isdigit(ch)) {v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=1e7+,INF=~0u>>;
const double eps=1e-;
/*******************template********************/
int dp[][];
void init(){
F(i,,) dp[][i]=;
F(i,,)
F(j,,)
F(k,,)
if (abs(j-k)>=) dp[i][j]+=dp[i-][k];
}
int solve(int n){
int len=,bit[];
for(;n;n/=) bit[++len]=n%;
bit[len+]=;
int ans=;
//长度为1~len-1的
F(i,,len-)
F(j,,)
ans+=dp[i][j];
//长度为len,但最高位没达到上界
F(j,,bit[len]-) ans+=dp[len][j];
//长度为len,且最高位达到上界
D(i,len-,){
F(j,,bit[i]-)
if (abs(j-bit[i+])>=) ans+=dp[i][j];
if (abs(bit[i]-bit[i+])<) break;
}
return ans;
}
int main(){
init();
int l,r;
while(scanf("%d%d",&l,&r)!=EOF)
printf("%d\n",solve(r+)-solve(l));
return ;
}