Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
488 B
1
Indexable
Never
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int memo[1000006];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++)
    {
        memo[i] = 2000000;
    }
    memo[n] = 0;
    for(int i = n; i >= 0; i--) {
        int tmp = i;
        while(tmp > 0) {
            int cifra = tmp % 10;
            memo[i - cifra] = min(memo[i - cifra], memo[i] + 1);
            tmp /= 10;
        }
    }
    cout << memo[0] << endl;
    return 0;
}