CSES - Shared codeLink to this code: https://cses.fi/paste/54fab72c7fe689a490ac0d/
#include<bits/stdc++.h>

using namespace std;

const int N =1e6 +10;

int dp[N]; // guarda menor caminho de n para 0

int main(){
    int n;
    cin >> n;
    dp[0] = 0;
    for(int num = 1;num <= n;num++){
        vector <int> d;
        int x = num;
        while(x > 0){
            int t = x % 10;
            d.push_back(t);
            x =x/10;
        }
        dp[num] = 1e7;
        for(auto y : d){
            dp[num] = min(dp[num], dp[num-y]+1);
        }
    }
    cout << dp[n] << '\n';
}