Advertisement
Nita_Cristian

Visul

Jan 25th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("vis.in");
  6. ofstream fout("vis.out");
  7.  
  8. int n, c, nr, a[21][21], posibilitati;
  9.  
  10. bool corect(int i, int j)
  11. {
  12.     return i >= 1 && i <= n && j <= n && j >= 1;
  13. }
  14.  
  15. void vis(int i, int j)
  16. {
  17.     if(i == n)
  18.     {
  19.         posibilitati++;
  20.         return;
  21.     }
  22.  
  23.     if(a[i+1][j] == 0 && corect(i+1, j))
  24.     {
  25.         vis(i+1, j);
  26.     }
  27.  
  28.     if(a[i+1][j-1] == 1 && corect(i+1, j-1))
  29.     {
  30.         vis(i+1, j-1);
  31.     }
  32.  
  33.     if(a[i+1][j+1] == 1 && corect(i+1, j+1))
  34.     {
  35.         vis(i+1, j+1);
  36.     }
  37. }
  38.  
  39. int main()
  40. {
  41.     fin >> n >> c >> nr;
  42.     for(int i = 1; i <= nr; i++)
  43.     {
  44.         int x, y;
  45.         fin >> x >> y;
  46.         a[x][y] = 1;
  47.     }
  48.     vis(1, c);
  49.  
  50.     fout << posibilitati;
  51.  
  52.     fin.close();
  53.     fout.close();
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement