Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //ifstream f("date.in");
- //ofstream g("date.out");
- int n, x[101];
- void afisare() {
- for(int i=1; i <= n; i++) cout << x[i];
- cout << '\n';
- }
- int bun(int i) {
- if(i == 1 and x[i] != 0) return 0;
- if(i == n and x[i] != 0) return 0;
- for(int j=1; j<i; j++)
- if(abs(x[j]-x[j+1]) != 1) return 0;
- return 1;
- }
- void back(int i) {
- while(i) {
- x[i]++;
- if(x[i] == n) x[i] = -1, i--;
- else if(bun(i)) {
- if(i == n) afisare();
- else i++;
- }
- }
- }
- int main() {
- cin >> n;
- for(int i=1; i<=n; i++) x[i] = -1;
- x[1] = 0;
- back(2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement