Advertisement
Saleh127

CSES 1637

Apr 29th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll dp[1000005];
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. cout.tie(0);
  11.  
  12.  
  13. ll n,m,i,j,k,l,d;
  14.  
  15. cin>>n;
  16.  
  17. for(i=1; i<=n; i++)
  18. {
  19. dp[i]=1e13;
  20. l=i;
  21.  
  22. while(l>0)
  23. {
  24. d=l%10;
  25. dp[i]=min(dp[i],dp[i-d]+1);
  26. l/=10;
  27. }
  28. }
  29.  
  30. cout<<dp[n]<<endl;
  31.  
  32. return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement