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