Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- const int MOD = 1e9 + 7;
- const int INF = 2e9 + 10;
- const int maxn = 1e6 + 5;
- int n;
- int dp[maxn];
- int main(){
- cin >> n;
- for(int i = 0; i <= n; ++i) {
- dp[i] = INF;
- }
- dp[n] = 0;
- for(int number = n; number >= 0; --number) {
- int tmp = number;
- while(tmp > 0) {
- int digit = tmp % 10;
- if(number - digit >= 0) {
- dp[number - digit] = min(dp[number - digit], dp[number] + 1);
- }
- tmp /= 10;
- }
- }
- cout << dp[0] << endl;
- }
- //869167734
- //869167734
Advertisement
Add Comment
Please, Sign In to add comment