比赛 2022级DP专题练习赛8 评测结果 AAAAAAAAAA
题目名称 同类分布 最终得分 100
用户昵称 op_组撒头屯 运行时间 3.382 s
代码语言 C++ 内存使用 14.55 MiB
提交时间 2023-03-01 19:36:04
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
int num[20],len,s;
ll f[20][170][170][2];
ll dp(int pt,int p,int sum,bool sm){
    if (sum>s)return 0;
    if (pt<=0)return (!p&&sum==s);
    if (f[pt][p][sum][sm]!=-1)return f[pt][p][sum][sm];
    int lim=(sm)?9:num[pt];ll ans=0;
    for (int i=0;i<=lim;i++){
        ans+=dp(pt-1,(10*p+i)%s,sum+i,sm|(i<num[pt]));
    }
    return f[pt][p][sum][sm]=ans;
}
ll solve(ll x){
    if (!x)return 0;
    len=0;
    while(x){
        num[++len]=x%10;x/=10;
    }ll ans=0;
    for (s=1;s<=len*9;s++){
        memset(f,-1,sizeof(f));
        ans+=dp(len,0,0,0);
    }
    return ans; 
}
int main(){
	freopen ("self.in","r",stdin);
	freopen ("self.out","w",stdout);
	ll a,b;scanf("%lld%lld",&a,&b);
	printf("%lld\n",solve(b)-solve(a-1));
}