Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, m, x[8];
- void Back(int k);
- void Write(int k);
- bool Ok(int k);
- int main()
- {
- cin >> n >> m;
- Back(1);
- return 0;
- }
- void Back(int k)
- {
- if(k > n)
- {
- Write(k - 1);
- return;
- }
- for(int i = 0; i < m; i++)
- {
- x[k] = i;
- if(Ok(k))
- Back(k + 1);
- }
- }
- bool Ok(int k)
- {
- if(k == 1 && x[k] == 0)
- return false;
- if(x[k] >= m)
- return false;
- return true;
- }
- void Write(int k)
- {
- for(int i = 1; i <= k; i++)
- cout << x[i];
- cout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement