又一个水暴了的数位dp
感觉数位dp相对于其他的dp来说,只是状态表示的维数多了一点,转移时需要注意的点多了一点,其他的好像也没什么
毕竟转移的时候要注意的地方,在我目前所做的数位dp中,都是一样的
存个代码好了(
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL dp[10][10];
int dig[10];
LL dfs(int pos,int pre,bool limit){
if(pos < 0)
return 1;
if(!limit && dp[pos][pre]!=-1)
return dp[pos][pre];
int bnd = limit?dig[pos]:9;
LL ret = 0;
for(int i=0;i<=bnd;i++){
if(i!=4 && !(pre==6 && i==2)){
ret += dfs(pos-1,i,limit && i==bnd);
}
}
if(!limit)
dp[pos][pre]=ret;
return ret;
}
LL cal(LL n){
memset(dp,-1,sizeof(dp));
int len = 0;
while(n){
dig[len++] = n%10;
n/=10;
}
return dfs(len-1,0,true);
}
int main(){
LL a,b;
while(cin>>a>>b && (a||b)){
cout<<cal(b)-cal(a-1)<<endl;
}
return 0;
}