Mirbek

Removing Digits

Dec 22nd, 2021
1,380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e6 + 5;
  6.  
  7. int n;
  8. int dp[N];
  9.  
  10. int main(){
  11.     cin >> n;
  12.  
  13.     for (int i = 1; i <= n; i++) {
  14.         dp[i] = 1e7;
  15.         int x = i;
  16.         while (x > 0) {
  17.             int d = x % 10;
  18.             dp[i] = min(dp[i], dp[i - d] + 1);
  19.             x /= 10;
  20.         }
  21.     }
  22.  
  23.     cout << dp[n] << endl;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment