• [暑假集训--数位dp]UESTC250 windy数


    windy定义了一种windy数。

    不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数。

    windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数?

    Input

    包含两个整数,AA BB 。

    满足 1AB20000000001≤A≤B≤2000000000 .

    OutputSample Input

    1 10

    Sample Output

    9

    记一下上一位出现的数是啥

     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 n,len,l,r;
    26 LL f[20][11][2];
    27 int d[110];
    28 inline LL dfs(int now,int dat,int lead,int fp)
    29 {
    30     if (now==1)return (!lead)||(lead&&dat==0);
    31     if (!fp&&f[now][dat][lead]!=-1)return f[now][dat][lead];
    32     LL ans=0,mx=fp?d[now-1]:9;
    33     for (int i=0;i<=mx;i++)
    34     {
    35         if (!lead&&(i==dat-1||i==dat||i==dat+1))continue;
    36         ans+=dfs(now-1,i,lead&&i==0&&now-1!=1,fp&&i==d[now-1]);
    37     }
    38     if (!fp)f[now][dat][lead]=ans;
    39     return ans;
    40 }
    41 inline LL calc(LL x)
    42 {
    43     if (!x)len=1,d[len]=0;
    44     else
    45     {
    46         LL xxx=x;
    47         len=0;
    48         while (xxx)
    49         {
    50             d[++len]=xxx%10;
    51             xxx/=10;
    52         }
    53     }
    54     LL sum=0;
    55     sum+=dfs(len,0,1,0);
    56     for (int i=1;i<=d[len];i++)
    57         sum+=dfs(len,i,0,i==d[len]);
    58     return sum;
    59 }
    60 int main()
    61 {
    62     while (~scanf("%lld%lld",&l,&r))
    63     {
    64         memset(f,-1,sizeof(f));
    65         printf("%lld
    ",calc(r)-calc(l-1));
    66     }
    67 }
    UESTC 250
  • 相关阅读:
    14.1.1 使用InnoDB 表的好处:
    7.5.1 Point-in-Time Recovery Using Event Times 使用Event Times 基于时间点恢复
    7.5 Point-in-Time (Incremental) Recovery Using the Binary Log 使用binay log 基于时间点恢复
    7.4.1 Dumping Data in SQL Format with mysqldump
    7.3.2 Using Backups for Recovery 使用备份用于恢复
    7.3.1 Establishing a Backup Policy
    RR 和RC隔离问题
    mark
    weblogic12
    转一篇对EJB理解的文章
  • 原文地址:https://www.cnblogs.com/zhber/p/7284476.html
Copyright © 2020-2023  润新知