数位DP
cxlove基础数位DP第一题
用容斥把所有的不吉利数字去掉就得到吉利数字的数量= =(满足区间减法)
//HDOJ 2089
#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=1e6+,INF=~0u>>;
const double eps=1e-;
/*******************template********************/
int dp[][];
void init(){
memset(dp,,sizeof dp);
dp[][]=;
F(i,,){
dp[i][]=dp[i-][]*-dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*+dp[i-][]+dp[i-][];
}
}
int solve(int n){
int len=,bit[];
int tmp=n;
for(;n;n/=) bit[++len]=n%;
bit[len+]=;
int ans=;
bool flag=false;
D(i,len,){
ans+=dp[i-][]*bit[i];
if (flag) ans+=dp[i-][]*bit[i];
if (!flag && bit[i]>) ans+=dp[i-][];
if (!flag && bit[i+]== && bit[i]>) ans+=dp[i][];
if (!flag && bit[i]>) ans+=dp[i-][];
if (bit[i]== || (bit[i+]== && bit[i]==)) flag=true;
}
return tmp-ans;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
init();
int n,m;
while(scanf("%d%d",&n,&m)!=EOF && n)
printf("%d\n",solve(m+)-solve(n));
return ;
}