[暑假集训--数位dp]hdu2089 不要62

杭州人称那些傻乎乎粘嗒嗒的人为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

要记一下上一位是不是6

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 #define mkp(a,b) make_pair(a,b)
16 #define pi 3.1415926535897932384626433832795028841971
17 using namespace std;
18 inline LL read()
19 {
20     LL x=0,f=1;char ch=getchar();
21     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
22     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
23     return x*f;
24 }
25 LL l,r,len;
26 LL f[20][11];
27 int d[20];
28 inline int dfs(int now,int lst,int fp)
29 {
30     if (now==1)return 1;
31     if (!fp&&f[now][lst]!=-1)return f[now][lst];
32     LL ans=0,mx=(fp?d[now-1]:9);
33     for (int i=0;i<=mx;i++)
34     {
35         if (lst==6&&i==2||i==4)continue;
36         ans+=dfs(now-1,i,fp&&mx==i);
37     }
38     if (!fp&&f[now][lst]==-1)f[now][lst]=ans;
39     return ans;
40 }
41 inline LL calc(LL x)
42 {
43     if (x==-1)return 0;
44     if (x==0)return 1;
45     LL xxx=x;
46     len=0;
47     while (xxx)
48     {
49         d[++len]=xxx%10;
50         xxx/=10;
51     }
52     LL sum=0;
53     for (int i=0;i<=d[len];i++)
54     if (i!=4)sum+=dfs(len,i,i==d[len]);
55     return sum;
56 }
57 int main()
58 {
59     memset(f,-1,sizeof(f));
60     while (~scanf("%d%d",&l,&r)&&l+r)printf("%lld
",calc(r)-calc(l-1));
61 }
hdu 2089

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read() {
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
LL n,len;
LL f[20][13][10][2];
int d[20];
inline int dfs(int now,int rest,int dat,int sat,int fp) {
if (now==1)return !rest&&sat;
if (!fp&&f[now][rest][dat][sat]!=-1)return f[now][rest][dat][sat];
LL ans=0,mx=(fp?d[now-1]:9);
for (int i=0;i<=mx;i++)
{
if (sat||!sat&&dat==1&&i==3)ans+=dfs(now-1,(rest*10+i)%13,i,1,fp&&mx==i);
else ans+=dfs(now-1,(rest*10+i)%13,i,0,fp&&mx==i);
}
if (!fp&&f[now][rest][dat][sat]==-1)f[now][rest][dat][sat]=ans;
return ans;
}
inline LL calc(LL x) {
LL xxx=x;
len=0;
while (xxx)
{
d[++len]=xxx%10;
xxx/=10;
}
LL sum=0;
for (int i=0;i<=d[len];i++)
sum+=dfs(len,i,i,0,i==d[len]);
return sum;
}
int main() {
memset(f,-1,sizeof(f));
while (scanf("%d",&n)!=EOF)printf("%lld ",calc(n));
}

原文地址:https://www.cnblogs.com/zhber/p/7284003.html