当前位置:网站首页>[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;
}
边栏推荐
- Thymeleaf application notes
- Sword finger offer 46. translate numbers into strings
- C # shelling tool for code encryption protection
- Huawei set up login with account and password
- clip:learning transferable visual models from natural language supervision
- Sword finger offer 45. arrange the array into the smallest number
- [leetcode] 1184. Distance between bus stops
- [shader realizes the flicker effect of three primary colors of television signal _shader effect Chapter 5]
- From code farmer to great musician, you only need these music processing tools
- [trial experience of Yuxin micro Wiota ad hoc network protocol development kit] RT thread BSP Software package production
猜你喜欢

English grammar_ Demonstrative pronoun this / these / that / those

Install MySQL 5.7.37 on windows10
![Leetcode 300 longest increasing subsequence (greedy + binary search for the first element subscript smaller than nums[i]), leetcode 200 island number (deep search), leetcode 494 target sum (DFS backtr](/img/60/6b75484a65a49c6e20c2b79c062310.png)
Leetcode 300 longest increasing subsequence (greedy + binary search for the first element subscript smaller than nums[i]), leetcode 200 island number (deep search), leetcode 494 target sum (DFS backtr

C # shelling tool for code encryption protection

Create a life cycle aware MVP architecture

Maya coffee machine modeling

YouTube "label products" pilot project launched
![[FreeRTOS] 10 event flag group](/img/c3/9f9c2ac4641f478575d48afd580b4b.png)
[FreeRTOS] 10 event flag group

Batch download files from the server to the local

Are network security and data security indistinguishable? Why is data security important?
随机推荐
Unit DLU of resource editor
Data transmission of different fragments in the same activity
6.0 holes stepped by fragment request permission in the system
Substr and substring function usage in SQL
Choose the appropriate container runtime for kubernetes
[leetcode] 1184. Distance between bus stops
Redis common configuration description
Login Huawei device in SSH mode
从码农转型大音乐家,你只差这些音乐处理工具
Solve the problem that gd32f207 serial port can receive but send 00
Rotation matrix derivation process
Codeforces round 580 (Div. 2) c- almost equal [Law]
Decorator of function
Expression evaluation (stack)
纯C实现----------尼科彻斯定理
vlan技术
存储类别
Look at the interface control devaxpress WinForms - how to customize auxiliary function properties (Part 2)
Sword finger offer 42. maximum sum of continuous subarrays
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