当前位置:网站首页>【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;
}
边栏推荐
- 全球不用交税的国家,为什么不交
- JS--hashchange事件--使用/教程
- Travel with Shengteng: See all the AI attractions in Jinling City in one day
- Mysql集群 ShardingSphere
- 2022-08-09 mysql/stonedb-子查询性能提升-概论
- The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module
- 如何知道电脑开机记录?
- JS--popstate事件--使用/教程/实例
- 离散选择模型之Gumbel分布
- CAD 连接两个相交线
猜你喜欢

SRv6性能测量

外包的水有多深?腾讯15k的外包测试岗能去吗?

经济衰退即将来临前CIO控制成本的七种方法

Mysql集群 ShardingSphere

Gartner's global integrated system market data tracking, hyperconverged market growth rate is the first

Mysql/stonedb - slow SQL - 2022-08-09 Q16 analysis

YGG 经理人杯总决赛已圆满结束,来看看这份文字版总结!

离散选择模型之Gumbel分布

ElasticSearcch集群

【面试高频题】可逐步优化的链表高频题
随机推荐
五分钟商学院(基础---商业篇)
一体化伺服电机在三轴钻孔机中的应用
【接口测试】requests 库请求体字符串解码
SRv6性能测量
力扣:377. 组合总和 Ⅳ
【云原生】一文讲透Kubevela addon如何添加腾讯Crane
[Cloud Native] This article explains how to add Tencent Crane to Kubevela addon
伦敦银行情中短线的支撑和阻力位
【哲理】事教人
金仓数据库 KingbaseGIS 使用手册(6.3. 几何对象创建函数)
【诗歌】枕上诗书
1018.值周
你的手机曾经被监控过吗?
How to know the computer boot record?
集合运算样例
中国SaaS企业排名,龙头企业Top10梳理
力扣:474.一和零
34. Fabric2.2 证书目录里各文件作用
如何正则匹配乱码?
安踏携手华为运动健康共同验证冠军跑鞋 创新引领中国体育