Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n;
- int a[3][3];
- int was[3][3];
- ll ans;
- bool check(int x, int y)
- {
- return x >= 0 && x < 3 && y >= 0 && y < 3;
- }
- void gen(int x, int y, ll res)
- {
- was[x][y] = 1;
- res = res * 10 + a[x][y];
- ans = max(res, ans);
- if (check(x + 1, y) && !was[x + 1][y])
- gen(x + 1, y, res), was[x + 1][y] = 0;
- if (check(x - 1, y) && !was[x - 1][y])
- gen(x - 1, y, res), was[x - 1][y] = 0;
- if (check(x, y - 1) && !was[x][y - 1])
- gen(x, y - 1, res), was[x][y - 1] = 0;
- if (check(x, y + 1) && !was[x][y + 1])
- gen(x, y + 1, res), was[x][y + 1] = 0;
- }
- int main()
- {
- n = 3;
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- cin >> a[i][j];
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < n; ++j)
- {
- for (int i1 = 0; i1 < n; ++i1)
- for (int j1 = 0; j1 < n; ++j1)
- was[i1][j1] = 0;
- gen(i, j, 0);
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement