SHARE
TWEET

Untitled

a guest Oct 21st, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, p, sol[10], m, c.p, k;
  6.  
  7. int main()
  8. {
  9.     cin >> n >> p;
  10.     sol[1] = p;
  11.     sol[n] = p;
  12.     back(2);
  13.     return 0;
  14. }
  15. int evalid(int k)
  16. {
  17.     for (int i = 1; i < k; i++)
  18.     {
  19.         if (sol[i] == sol[k])
  20.            return false;
  21.         if (abs(sol[i] - sol[i + 1]) != 1)
  22.             return
  23.        
  24.     }
  25.        
  26.     return true;
  27. }
  28. void back(int k)
  29. {
  30.     if (k > n)
  31.         afis();
  32.     else
  33.         for (int i =n; i >= 1; i--)
  34.         {
  35.             sol[k] = i;
  36.             if (evalid(k))
  37.                 back (k + 1);
  38.         }
  39. }
  40. void afis()
  41. {
  42.     for (int i = 1; i <= n; i++)
  43.         cout << sol[i] << " ";
  44.     cout << endl;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top