Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("soarece.in");
  5. ofstream fout("soarece.out");
  6. int n,m,a[21][21],t[21][21],li,ci,lf,cf,nrsol;
  7. int dl[]={0,-1,0,1,0};
  8. int dc[]={0,0,1,0,-1};
  9. void citire()
  10. {
  11. int i,j;
  12. fin>>n>>m;;
  13. for(i=1;i<=n;i++)
  14. for(j=1;j<=m;j++)
  15. fin>>a[i][j];
  16. fin>>li>>ci>>lf>>cf;
  17. }
  18. void afis()
  19. {
  20. nrsol++;}
  21. void traseu(int l, int c, int pas)
  22. {
  23. int ln,cn,k;
  24. for(k=1;k<=4;k++)
  25. {
  26. ln=l+dl[k];
  27. cn=c+dc[k];
  28. if(ln>=1 && ln<=n && cn>=1 &&cn<=m)
  29. if(a[ln][cn]==0 &&t[ln][cn]==0)
  30. {
  31. t[ln][cn]=pas;
  32. if(ln==lf && cn==cf)
  33. afis();
  34. else
  35. traseu(ln,cn,pas+1);
  36. t[ln][cn]=0;
  37. }
  38. }
  39.  
  40. }
  41. int main()
  42. {
  43. citire();
  44. t[li][ci]=1;
  45. traseu (li,ci,2);
  46. fout<<nrsol;;
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement