fzu 2113 Jason的特殊爱好 --- 数位dp

这题目名字起的真龊。。。


#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
#define ll __int64
using namespace std;

ll dp[30][20],a,b,num[30];

ll dfs(ll n,ll pos,bool flag)
{
    if(pos==-1) return n;
    if(!flag&&dp[pos][n]!=-1) return dp[pos][n];
    ll ans=0,p;
    if(flag) p=num[pos];
    else p=9;
    for(ll i=0;i<=p;i++)
    {
        if(i==1) ans+=dfs(n+1,pos-1,flag&&i==p);//这里写成了num[i] 一直错 终于理解了这个dfs
        else ans+=dfs(n,pos-1,flag&&i==p);
    }
    if(!flag) dp[pos][n]=ans;
    return ans;
}

ll cal(ll x)
{
    ll l=0;
    while(x)
    {
        num[l++]=x%10;
        x/=10;
    }
    return dfs(0,l-1,1);
}


int main()
{
    memset(dp,-1,sizeof dp);
    while(~scanf("%I64d%I64d",&a,&b))
    {
        if(a>b) swap(a,b);
        printf("%I64d\n",cal(b)-cal(a-1));
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值