daily pastebin goal
14%
SHARE
TWEET

Untitled

AlejandroGY Feb 22nd, 2018 (edited) 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2. #include <utility>
  3. #include <algorithm>
  4.  
  5. int n;
  6. int contador;
  7. int fila_de[12];
  8.  
  9. void solve(int i) {
  10.     if (i == n) {
  11.         ++contador;
  12.         return;
  13.     }
  14.  
  15.     for (int j = 0; j < n; ++j) {
  16.         if (i == 0) {
  17.             if (fila_de[j] == -1) {
  18.                 fila_de[j] = i;
  19.                 solve(i + 1);
  20.                 fila_de[j] = -1;
  21.             }
  22.         } else if (j == 0) {
  23.             if (fila_de[j] == -1 && fila_de[j + 1] != (i - 1)) {
  24.                 fila_de[j] = i;
  25.                 solve(i + 1);
  26.                 fila_de[j] = -1;
  27.             }
  28.         } else if (j == n - 1) {
  29.             if (fila_de[j] == -1 && fila_de[j - 1] != (i - 1)) {
  30.                 fila_de[j] = i;
  31.                 solve(i + 1);
  32.                 fila_de[j] = -1;
  33.             }
  34.         } else {
  35.             if (fila_de[j] == -1 && fila_de[j - 1] != (i - 1) && fila_de[j + 1] != (i - 1)) {
  36.                 fila_de[j] = i;
  37.                 solve(i + 1);
  38.                 fila_de[j] = -1;
  39.             }
  40.         }
  41.     }
  42. }
  43.  
  44. int main( ) {
  45.     std::fill(fila_de, fila_de + 12, -1);
  46.     std::scanf("%d", &n);
  47.     solve(0);
  48.     std::printf("%d\n", contador);
  49. }
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