• XDU 1160




    Problem 1160 - 科协的数字游戏I
    Time Limit: 1000MS   Memory Limit: 65536KB   Difficulty
    Total Submit: 184  Accepted: 32  Special Judge: No
    Description

     科协里最近很流行数字游戏。某人命名了一种不降数,这种数字必须满足从左到右各位数字成大于等于的关系,如123,446。现在大家决定玩一个游戏,指定一个整数闭区间[a,b],问这个区间内有多少个不降数。

    Input
    题目有多组测试数据。每组只含2个数字a, b (1 <= a, b <= 2^31)。
    Output
    每行给出一个测试数据的答案,即[a, b]之间有多少阶梯数。
    Sample Input
    1 9 
    1 19
    Sample Output
    9
    18
    Hint
    Source
                tclh123 



    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    int a,b,dp[20][20],bit[20];

    int dfs(int pos,int s,bool limit)
    {
        if(pos==-1return 1;
        if(!limit&&~dp[pos][s]) return dp[pos][s];
        int end=limit?bit[pos]:9;
        int ans=0;
        for(int i=s;i<=end;i++)
            ans+=dfs(pos-1,i,limit&&(i==end));
        if(!limit)
            dp[pos][s]=ans;
        return ans;
    }

    int main()
    {
        memset(dp,-1,sizeof(dp));
        while(scanf("%d%d",&a,&b)!=EOF)
        {
            int len=0;
            a--;
            while(a)
            {
                bit[len++]=a%10;
                a/=10;
            }
            int A=dfs(len-1,0,true);
            len=0;
            while(b)
            {
                bit[len++]=b%10;
                b/=10;
            }
            int B=dfs(len-1,0,true);
            printf("%d ",B-A);
        }

        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Manni )


  • 相关阅读:
    1059. Prime Factors (25)
    mybatis中resultType和resultMap的区别
    Spring Boot中使用Swagger2构建强大的RESTful API文档
    ES6之6种遍历对象属性的方法
    QQ授权登录
    nodejs爬虫入门
    nrm -- NPM registry 管理工具(附带测速功能)
    Sublime Text 3 使用MarkDown编写带预览的文本
    js中字符串函数indexOf与search的区别
    linux基础入门
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350845.html
Copyright © 2020-2023  润新知