fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. int mini(int a,int b,int c)
  5. {
  6. return min(a,min(b,c)) ;
  7. }
  8.  
  9. int solve(int x)
  10. {
  11. int dp[x+1]={0};
  12. dp[1]=0;
  13. dp[2]=1;
  14. int i = 3 ;
  15. while(i<=x)
  16. {
  17. if(i%7==0)
  18. {
  19. dp[i]=mini(dp[i-1]+1,dp[i-2]+1,dp[i/7]+ 1) ;
  20. }
  21. else
  22. {
  23. dp[i]=min(dp[i-1]+1,dp[i-2]+1) ;
  24. }
  25. i++;
  26. }
  27. return dp[x] ;
  28. }
  29. int main()
  30. {
  31.  
  32. int x = 93 ;
  33. cout<<"Minimum number of steps required to make the given number to 1"<<solve(x);
  34.  
  35. return 0 ;
  36. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Minimum number of steps required to make the given number to 16