BZOJ-3679(数位DP)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b;
int k[20];
ll dp[20][10][2];
ll dfs(int pos,int x,bool lead,bool limit){
    if(pos == -1)return !lead;
    if(!limit && !lead && dp[pos][x])return dp[pos][x];
    int up = limit ? k[pos] : 9;
    ll res = 0;
    for(int i=0;i<=up;i++){
        if(lead){
            if(i == 0){
                res += dfs(pos-1,x,lead,false);
            }
            else{
                res += (x == i ? 2ll : 1ll) * dfs(pos-1,x,false,limit && k[pos] == i);
            }
        }
        else{
            res += (x == i ? 2ll : 1ll) * dfs(pos-1,x,false,limit && k[pos] == i);
        }
    }
    if(!limit && !lead)dp[pos][x] = res;
    return res;
}
ll solve(ll x,int z){
    int pos = 0;
    while(x){
        k[pos++] = x%10;
        x/=10;
    }
    return dfs(pos-1,z,true,true);
}
int main(){
    scanf("%lld%lld",&a,&b);
    for(int i=0;i<=9;i++){
        printf("%lld ",solve(b,i) - solve(a-1,i));
    }
    puts("");
    return 0;
}

转载于:https://www.cnblogs.com/1625--H/p/10876701.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值