Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int l, lmax, verif_trecere[26];
  5.  
  6. void rezolvare (int x, int y, char s[21][21], int R, int C)
  7. {
  8. if (verif_trecere[s[x][y] - 'A'] || x < 0 || y < 0 || x >= R || y >= C)
  9. return;
  10. verif_trecere[s[x][y] - 'A'] = 1;
  11. ++l;
  12. if (l > lmax)
  13. lmax = 1;
  14. rezolvare(x-1, y, s, R, C);
  15. rezolvare(x+1, y, s, R, C);
  16. rezolvare(x, y-1, s, R, C);
  17. rezolvare(x, y+1, s, R, C);
  18. verif_trecere[s[x][y] - 'A'] = 0;
  19. --l;
  20. }
  21.  
  22. int main()
  23. {
  24. int R, C;
  25. char s[21][21];
  26. ifstream fin("monkey.in");
  27. ofstream fout("monkey.out");
  28. fin >> R >> C;
  29. for (int i = 0; i < R; ++i)
  30. for (int j = 0; j < C; ++j)
  31. fin >> s[i][j];
  32. rezolvare(0, 0, s, R, C);
  33. fout << lmax;
  34. fin.close();
  35. fout.close();
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement