当前位置:网站首页>【集训DAY8】Interesting Number 【数位DP】
【集训DAY8】Interesting Number 【数位DP】
2022-07-21 07:15:00 【VL——MOESR】
思路:
一道数位DP的板子题
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) {
//cout<<x<<' '<<sum<<' '<<k<<' '<<r<<' '<<limit<<endl;
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][k][sum][r] != tmp && f[x][k][sum][r] != -1)
// cout<<"dsfdsafasdf"<<endl;
if(!limit) f[x][sum][r] = tmp;
// cout<<tmp<<endl;
return tmp;
}
int main() {
freopen("number.in", "r", stdin);
freopen("number.out", "w", stdout);
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;
}
边栏推荐
- Markdown 转 PDF API 数据接口
- Mysql06 (sequence)
- C managed and unmanaged resources
- 创建并发索引时失败,遗留了一个失效的索引 ,如何查找
- 七甲川染料CY7标记肽核酸PNA合成方法CY7-PNA
- Hardcore Fiddler packet capturing tool large strategy (end) Fiddler ultimate
- Selenium被检测为爬虫,怎么屏蔽和绕过
- 45: Chapter 4: developing file services: 6: third party cloud storage solutions [Alibaba cloud OSS]; (purchase OSS services; subscribe to services; create a bucket;)
- UnityWebGl项目总结(未完)
- XMLDecoder解析流程分析
猜你喜欢
45: Chapter 4: developing file services: 6: third party cloud storage solutions [Alibaba cloud OSS]; (purchase OSS services; subscribe to services; create a bucket;)
LeetCode 10. 正则表达式匹配
“我放弃编程,写了一本130万字的硬科幻小说”
Detailed explanation and typical cases of multi-agent system cluster collaborative control experimental platform
软件测试需要学习什么?
nslookup命令使用
一种新的UI测试方法:视觉感知测试
【愚公系列】2022年7月 Go教学课程 014-运算符之算术运算符
Appium自动化框架升级到最新的2.0
[paper notes] 3D point cloud segmentation pointnet
随机推荐
The NSLOOKUP command uses
Vscode running C language file
零基础转行软件测试学习要不要报培训班学习,还是自学好?
【JVM】垃圾收集器的选择
2022年化工自动化控制仪表考试试题模拟考试平台操作
连接远程服务器的vscode无法格式化代码/文档(已解决)
LeetCode 10. 正则表达式匹配
JS get the server IP, port and protocol
Can multithreading optimize program performance?
Mysql08(事务)
软件测试需要学习什么?
酪氨酸修饰肽核酸PNA|Tyr-PNA|Bz-Tyr-PNA|99Tcm—survivinmRNA反义肽核酸的使用方法
ModuleNotFoundError: No module named ‘pysat.solvers‘(已解决)
What is the difference between int *const p= & I and int const *p= & I
How to understand pointers?
Deploy server
easyexcel简单使用
Software resources Encyclopedia
Installation du gestionnaire de loisirs
使用CompletableFuture实现异步回调