码迷,mamicode.com
首页 > 其他好文 > 详细

How Many Zeroes? LightOJ - 1140

时间:2018-08-01 16:38:58      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:scan   判断   def   初始   any   cto   lld   stdio.h   lightoj   

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iostream>
#include<ctype.h>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
using namespace std;
#define LL long long
LL dp[55][55],num[55];
LL dfs(int pos,int iszero,int st,int limit)//pow为数位,iszero判断是否为0,st上一个状态初始为0,limit是否达到上限
{
    if(pos<0)
    {
        if(iszero)
            return 1;
        else
            return st;
    }
    if(!limit&&!iszero&&dp[pos][st]!=-1)
        return dp[pos][st];
    LL ans=0;
    int len=limit?num[pos]:9;
    for(int i=0;i<=len;i++)
    {
        if(iszero)
            ans+=dfs(pos-1,i==0,0,limit&&i==len);
        else
            ans+=dfs(pos-1,0,st+(i==0),limit&&i==len);
    }
    if(!limit&&!iszero)
        dp[pos][st]=ans;
    return ans;

}
LL sv(LL a)
{
    int len=0;
    memset(dp,-1,sizeof(dp));
    memset(num,0,sizeof(num));
    while(a)
    {
        num[len++]=a%10;
        a/=10;
    }
    return dfs(len-1,1,0,1);
}
int main()
{
    LL m,n;
    while(~scanf("%lld%lld",&n,&m))
    {
      //  LL ee=sv(m)-sv(n-1);
        printf("%lld\n",sv(m)-sv(n-1));
    }

}

 

How Many Zeroes? LightOJ - 1140

标签:scan   判断   def   初始   any   cto   lld   stdio.h   lightoj   

原文地址:https://www.cnblogs.com/nr1999/p/9401938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!