ABC208E(bug代码。。。。qwq。。。qwq)(顺便学习了下如何使用内部类)

今天的e

挺模板的,主要是难在证明,一开始to_string后忘记 -‘0’,手都打断

#include <string>
#include <map>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#define For(i,x,y) for(int i = (x); i <= (y); i ++ )
typedef long long LL;
using namespace std;
LL n, k;
string num;
map<LL,LL>dp[30];

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}
 
  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}
/*
100 
80
*/
void sol(){
    cin>>n>>k;
    num = to_string(n);
    //cout<<num<<endl;
    reverse(num.begin(),num.end());
    int tot = num.size();
    num = " " + num;
    For(i,1,tot) num[i] -= '0';
    //cout<<num<<endl;
    auto dfs = MFP([&](auto dfs,bool limit, bool zero, LL dep, LL sta) -> LL{
        if(dep  == 0) return (sta<=k);
        if(sta > k) sta = k + 1;
        if(!limit && !zero && (dp[dep].count(sta))) return dp[dep][sta];
        //LL& ans = dp[dep][sta];
        int up = limit ? num[dep] : 9;
        LL res = 0;
        
        for(int i = 0; i <= up; i ++ ){
            res += dfs(limit&&i==up, zero && i == 0, dep-1, zero && i == 0?1:sta*i);
        }
       // cout<<dep<<' '<<sta<<' '<<res<<' '<<num[dep]<<endl;
        if(!limit && !zero) dp[dep][sta] = res;
        return res;
    });
    cout<<dfs(true,true,tot,1)-1<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    sol();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值