Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("soarece.in");
  7. ofstream g("soarece.out");
  8.  
  9. int a[101][101],n,m,i1,j1,i2,j2,s;
  10. int d[4]= {-1,0,1,0}, dc[4]= {0,1,0,-1};
  11.  
  12.  
  13.  
  14. void bkt(int k, int l, int c)
  15. {
  16. for(int i=0; i<4; i++)
  17. {
  18. int x=l+d[i], y=c+dc[i];
  19. if(x>0 && x<=n && y>0 && y<=m && a[x][y]==0)
  20. {
  21. a[x][y]=2;
  22. if(x==i2&&y==j2)
  23. s++;
  24. else
  25. bkt(k+1,x,y);
  26. a[x][y]=0;
  27. }
  28. }
  29. }
  30.  
  31. int main()
  32. {
  33. f>>n>>m;
  34. for(int i=1; i<=n; i++)
  35. for(int j=1; j<=m; j++)
  36. f>>a[i][j];
  37.  
  38. f>>i1>>j1>>i2>>j2;
  39. a[i1][j1]=1;
  40. bkt(2,i1,j1);
  41. g<<s;
  42. return 0;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement