Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int l, lmax, verif_trecere[26];
- void rezolvare (int x, int y, char s[21][21], int R, int C)
- {
- if (verif_trecere[s[x][y] - 'A'] || x < 0 || y < 0 || x >= R || y >= C)
- return;
- verif_trecere[s[x][y] - 'A'] = 1;
- ++l;
- if (l > lmax)
- lmax = 1;
- rezolvare(x-1, y, s, R, C);
- rezolvare(x+1, y, s, R, C);
- rezolvare(x, y-1, s, R, C);
- rezolvare(x, y+1, s, R, C);
- verif_trecere[s[x][y] - 'A'] = 0;
- --l;
- }
- int main()
- {
- int R, C;
- char s[21][21];
- ifstream fin("monkey.in");
- ofstream fout("monkey.out");
- fin >> R >> C;
- for (int i = 0; i < R; ++i)
- for (int j = 0; j < C; ++j)
- fin >> s[i][j];
- rezolvare(0, 0, s, R, C);
- fout << lmax;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement