hdu2089 不要62
与前面几个类似,多开几维处理他的要求。
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set> 10 using namespace std; 11 #define N 100000 12 #define LL long long 13 #define INF 0xfffffff 14 const double eps = 1e-8; 15 const double pi = acos(-1.0); 16 const double inf = ~0u>>2; 17 int dp[10][2][2]; 18 int d[10]; 19 int dfs(int i,int e,int o,int p) 20 { 21 if(i==-1) 22 { 23 return p; 24 } 25 if(!e&&dp[i][o][p]!=-1) return dp[i][o][p]; 26 int mk = e?d[i]:9; 27 int ans = 0; 28 for(int j = 0 ; j <= mk ; j++) 29 { 30 if(p) 31 ans+=dfs(i-1,e&&j==mk,0,1); 32 else 33 { 34 if(o==1&&j==2) 35 ans+=dfs(i-1,e&&j==mk,0,1); 36 else if(j==4) 37 ans+=dfs(i-1,e&&j==mk,0,1); 38 else if(j==6) 39 ans+=dfs(i-1,e&&j==mk,1,0); 40 else 41 ans+=dfs(i-1,e&&j==mk,0,0); 42 } 43 } 44 return e?ans:dp[i][o][p] = ans; 45 } 46 int cal(int x) 47 { 48 int g = 0; 49 while(x) 50 { 51 d[g++] = x%10; 52 x/=10; 53 } 54 return dfs(g-1,1,0,0); 55 } 56 57 int main() 58 { 59 int n,m; 60 memset(dp,-1,sizeof(dp)); 61 while(cin>>n>>m) 62 { 63 if(!n&&!m) break; 64 cout<<(m-n+1)-(cal(m)-cal(n-1))<<endl; 65 } 66 return 0; 67 }