Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int dp[1000000];
- int cifra(int n){
- if(n==0){
- return 0;
- }
- if(dp[n]!=-1){
- return 0;
- }
- int backup_n=n;
- int najgolem=0;
- while(n>0){
- if(n%10>najgolem){
- najgolem=n%10;
- }
- n/=10;
- }
- return dp[n] = cifra(backup_n-najgolem)+1;
- }
- int main()
- {
- int n;
- cin>>n;
- for(int i=0; i<=n; i++){
- dp[i]=-1;
- }
- cout<<cifra(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement