Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n, m, x[8];
  5.  
  6. void Back(int k);
  7. void Write(int k);
  8. bool Ok(int k);
  9.  
  10. int main()
  11. {
  12. cin >> n >> m;
  13. Back(1);
  14. return 0;
  15. }
  16.  
  17. void Back(int k)
  18. {
  19. if(k > n)
  20. {
  21. Write(k - 1);
  22. return;
  23. }
  24.  
  25. for(int i = 0; i < m; i++)
  26. {
  27. x[k] = i;
  28. if(Ok(k))
  29. Back(k + 1);
  30. }
  31.  
  32. }
  33.  
  34. bool Ok(int k)
  35. {
  36. if(k == 1 && x[k] == 0)
  37. return false;
  38. if(x[k] >= m)
  39. return false;
  40. return true;
  41. }
  42.  
  43. void Write(int k)
  44. {
  45. for(int i = 1; i <= k; i++)
  46. cout << x[i];
  47. cout << '\n';
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement