hdu 2089 不要62 (数位dp)

Description

杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。

Input

输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。

Output

对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。

Sample Input

1 100
0 0

Sample Output

80

跟上两道数位dp差不多。直接上代码了。
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 int bit[11],dp[11][11];
 5 int dfs (int pos,int pre,bool e,bool z)//pre表示前一位数字
 6 {
 7     if (pos==-1) return 1;
 8     if (!e&&dp[pos][pre]!=-1) return dp[pos][pre];
 9     long long ans=0;
10     int endd=e?bit[pos]:9;
11     for (int i=0;i<=endd;++i)
12     {
13         if (i==4)
14         continue;
15         if (!(i==2&&pre==6))
16         ans+=dfs(pos-1,i,e&&i==endd,z&&(i==0));
17     }
18 
19     if (!e) dp[pos][pre]=ans;
20     return ans;
21 }
22 int calc (int n)
23 {
24     int len=0;
25     while (n)
26     {
27         bit[len++]=n%10;
28         n/=10;
29     }
30     return dfs(len-1,-1,1,1);
31 }
32 int main()
33 {
34     int m,n;
35     memset(dp,-1,sizeof dp);
36     //freopen("de.txt","r",stdin);
37     while (~scanf("%d%d",&n,&m))
38     {
39         if (n==0&&m==0)
40         break;
41         printf("%d
",calc(m)-calc(n-1));
42     }
43     return 0;
44 }
 
原文地址:https://www.cnblogs.com/agenthtb/p/5911914.html