当前位置:网站首页>【SSL集训DAY2】有趣的数【数位DP】
【SSL集训DAY2】有趣的数【数位DP】
2022-08-09 22:35:00 【VL——MOESR】

思路:
c o d e code code
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
ll n, ans, len;
ll f[21][163][163];
ll lim[20], a[20];
inline ll dfs(register ll x, register ll sum, register ll k, register ll r, register ll limit) {
if(x > len && sum == 0 && r == 0) {
f[x][sum][r] = 1;
return 1;
}
if(x > len) {
f[x][sum][r] = 0;
return 0;
}
if(!limit && f[x][sum][r] != -1) return f[x][sum][r];
register ll tmp = 0;
if(limit) {
for(register ll i = 0; i <= lim[x]; ++ i)
if(sum - i >= 0)
tmp += dfs(x + 1, sum - i, k, (r * 10 + i) % k, i == lim[x]);
}
else {
for(register ll i = 0; i <= 9; ++ i)
if(sum - i >= 0)
tmp += dfs(x + 1, sum - i, k, (r * 10 + i) % k, 0);
}
if(!limit) f[x][sum][r] = tmp;
return tmp;
}
int main() {
scanf("%lld", &n);
register ll m = n;
while(m != 0) {
++ len;
a[len] = m % 10;
m /= 10;
}
for(register ll i = 1; i <= len; ++ i) lim[i] = a[len - i + 1];
for(register ll i = 1; i <= len * 9; ++ i)
{
memset(f, -1, sizeof(f));
ans += dfs(1, i, i, 0, 1);
}
printf("%lld", ans);
return 0;
}
边栏推荐
- ABAP中Collect的用法
- 经济衰退即将来临前CIO控制成本的七种方法
- k8s部署mysql
- 2022-08-09 mysql/stonedb-慢SQL-Q16分析
- Force Buckle: 474. Ones and zeros
- 全球不用交税的国家,为什么不交
- 杭电多校-Counting Stickmen-(思维+组合数+容斥)
- Gartner's global integrated system market data tracking, hyperconverged market growth rate is the first
- YGG 经理人杯总决赛已圆满结束,来看看这份文字版总结!
- Gumbel distribution of discrete choice model
猜你喜欢

complete knapsack theory

IT传奇人物菲尔德的转型经验教训及给CIO的建议

How to match garbled characters regularly?

离散选择模型之Gumbel分布

带着昇腾去旅行:一日看尽金陵城里的AI胜景
![[Interface Test] Decoding the request body string of the requests library](/img/99/82ef792dacd398a8a62dd94f235a91.png)
[Interface Test] Decoding the request body string of the requests library

完全背包理论

Technology feast!Huayun Data brings six topics to OpenInfra Days China

2022年最新《谷粒学院开发教程》:10 - 前台支付模块

Comprehensive analysis of FPGA basics
随机推荐
[Interface Test] Decoding the request body string of the requests library
Gumbel distribution of discrete choice model
[JZOF] 82 binary tree with a path of a certain value (1)
leetcode 20. Valid Parentheses 有效的括号(中等)
HStreamDB v0.9 发布:分区模型扩展,支持与外部系统集成
Sqlserver限制账户在哪些ip下才可以访问数据库
Filament - Material basic graphics drawing
2022-08-09 mysql/stonedb-子查询性能提升-概论
测试2年,当时身边一起入行的朋友已经月薪20k了,自己还没过万,到底差在了哪里?
MVC与MVVM模式的区别
数据库优化 | 干货
Leetcode 235. 二叉搜索树的最近公共祖先
国内BI厂商一览
What are the Shenzhen fortress machine manufacturers?Which one do you recommend?
后台管理实现导入导出
torch.distributed多卡/多GPU/分布式DPP(二)——torch.distributed.all_reduce(reduce_mean)&barrier&控制进程执行顺序&随机数种子
【诗歌】枕上诗书
2020年度SaaS TOP100企业名单
tiup cluster start
34. Fabric2.2 证书目录里各文件作用