Advertisement
STANAANDREY

soarece 23/11/2020

Nov 23rd, 2020 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. //https://www.pbinfo.ro/probleme/342/soarece
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. ifstream fin("soarece.in");
  7. ofstream fout("soarece.out");
  8.  
  9. int n, m, is, js, ib, jb, a[11][11], nrsol = 0;
  10.  
  11. const int di[] = {0, 0, 1, -1}, dj[] = {1, -1, 0, 0};
  12.  
  13. void afis() {
  14.   nrsol++;
  15. }
  16.  
  17. void back(int i, int j, int pas) {
  18.   if (i > 0 && i <= n && j > 0 && j <= m && a[i][j] == 0) {
  19.     a[i][j] = pas;
  20.     if (i == ib && j == jb)
  21.       afis();
  22.     else
  23.       for (int k = 0; k < 4; ++k)
  24.         back(i + di[k], j + dj[k], pas + 1);
  25.     a[i][j] = 0;
  26.   }
  27. }
  28.  
  29. int main() {
  30.   fin >> n >> m;
  31.   for (int i = 1; i <= n; ++i)
  32.     for (int j = 1; j <= m; ++j)
  33.       fin >> a[i][j], a[i][j] = -a[i][j];
  34.   fin >> is >> js >> ib >> jb;
  35.   back(is, js, 1);
  36.   fout << nrsol;
  37.   return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement