当前位置:网站首页>[training Day8] interesting number [digital DP]
[training Day8] interesting number [digital DP]
2022-07-24 20:10:00 【VL——MOESR】

Ideas :
One digit DP The board question of
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;
}
边栏推荐
- Expression evaluation (stack)
- ATL container - catlmap, crbmap
- Substr and substring function usage in SQL
- Basic idea of regularization
- 英文翻译中文常见脏话
- Implementation of OA office system based on JSP
- Recursion of function [easy to understand]
- Choose the appropriate container runtime for kubernetes
- Redisgraph graphic database multi activity design scheme
- Sword finger offer 40. minimum number of K
猜你喜欢
![Microservice architecture | service monitoring and isolation - [sentinel] TBC](/img/28/8ca90e9dbd492688e50446f55959ff.png)
Microservice architecture | service monitoring and isolation - [sentinel] TBC

Xiaomi 12s ultra products are so powerful, but foreigners can't buy Lei Jun: first concentrate on the Chinese market

Lights of thousands of families in the year of xinchou

Istio二之流量劫持过程

Apache atlas version 2.2 installation

Rotation matrix derivation process

English grammar_ Demonstrative pronoun this / these / that / those

C # shelling tool for code encryption protection
![[Extension Program - cat scratch 1.0.15 _ online video and audio acquisition artifact _ installation tutorial plus acquisition]](/img/75/5eca7f63758802ecf86a90a1bbdeaf.png)
[Extension Program - cat scratch 1.0.15 _ online video and audio acquisition artifact _ installation tutorial plus acquisition]

Thymeleaf application notes
随机推荐
Storage category
Connect the smart WiFi remote control in the home assistant
[German flavor] safety: how to provide more protection for pedestrians
Analysis and Simulation of strlen function
Functional test of redisgraph multi active design scheme
Machine learning job interview summary: five key points that resume should pay attention to
Are network security and data security indistinguishable? Why is data security important?
A circle is displayed and can be moved
Click the button to return to the top smoothly
Choose the appropriate container runtime for kubernetes
Lights of thousands of families in the year of xinchou
147 set whether to cache by using the routing meta information - use of include and exclude - use of activated and deactivated
Qt| control qscrollbar display position
872. Maximum common divisor
How to use the interface control telerik UI for WinForms development step progress bar?
Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr
Make Huawei router into FTP server (realize upload and download function)
《自尊的6大支柱》自尊来源于自身的感受
【LeetCode】1184. 公交站间的距离
Monotone stack and monotone queue (linear complexity optimization)