zoukankan      html  css  js  c++  java
  • UESTC250 windy数 (相邻两数之差不小于2) 数位dp

    题意:http://acm.uestc.edu.cn/#/problem/show/250

    windy定义了一种windy数。

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

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

    Input

    包含两个整数,B 。

    满足 1AB20000000001≤A≤B≤2000000000 .

    OutputSample Input

    1 10

    Sample Output

    9
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<map>
    #include<vector>
    #include<math.h>
    #include<string>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define LL long long
    #define N 106
    #define Lson rood<<1
    #define Rson rood<<1|1
    LL dp[40][12][3],d[60];
    LL dfs(int now,int up,int falg,int fp)
    {
        if(now==1) return (!falg)||(falg&&!up);
        if(!fp&&dp[now][up][falg]!=-1) return dp[now][up][falg];
        LL ans=0;
        int ma=fp?d[now-1]:9;
        for(int i=0;i<=ma;i++)
        {
            if(!falg&&abs(i-up)<2) continue;
            ans+=dfs(now-1,i,falg&&i==0&&now-1!=1,fp&&i==ma);
        }
        if(!fp&&dp[now][up][falg]==-1) dp[now][up][falg]=ans;
        return ans;
    }
    LL calc(LL x)
    {
        if(x==0) return 1;
        LL xxx=x;
        int 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()
    {
        LL l,r;
        memset(dp,-1,sizeof(dp));
        while(scanf("%lld%lld",&l,&r)!=EOF)
            printf("%lld
    ",calc(r)-calc(l-1));
        return 0;
    }
  • 相关阅读:
    POJ 1905 Expanding Rods 木棍膨胀
    [JSOI2007] 文本生成器
    18.09.22模拟赛T2 历史
    [USACO18OPEN] Talent Show
    [国家集训队] 整数的lqp拆分
    [HNOI2008] GT考试
    读入优化效果测试
    Trie图 模板
    manacher算法 详解+模板
    [洛谷P4299] 首都
  • 原文地址:https://www.cnblogs.com/a719525932/p/7770572.html
Copyright © 2011-2022 走看看