XDU 1160 - 科协的数字游戏I



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\n",B-A);
    }

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


转载于:https://www.cnblogs.com/CKboss/p/3350845.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值