Advertisement
Josif_tepe

Untitled

Oct 20th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int dp[1000000];
  5. int cifra(int n){
  6.     if(n==0){
  7.         return 0;
  8.     }
  9.     if(dp[n]!=-1){
  10.         return 0;
  11.     }
  12. int backup_n=n;
  13. int najgolem=0;
  14. while(n>0){
  15.     if(n%10>najgolem){
  16.         najgolem=n%10;
  17.     }
  18.     n/=10;
  19. }
  20.  
  21. return dp[n] =  cifra(backup_n-najgolem)+1;
  22.  
  23. }
  24.  
  25. int main()
  26. {
  27.     int n;
  28.     cin>>n;
  29.     for(int i=0; i<=n; i++){
  30.         dp[i]=-1;
  31.     }
  32.     cout<<cifra(n);
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement