diff --git a/S2OJ/1200/1200.cpp b/S2OJ/1200/1200.cpp new file mode 100644 index 00000000..871365e3 --- /dev/null +++ b/S2OJ/1200/1200.cpp @@ -0,0 +1,52 @@ +#include +#include + +using std::cin; +using std::cout; +using std::endl; + +const long long mod = 281474976710656; + +int n; +long long ans; +char g[505][505]; + +void dfs1(int, int, std::vector); +long long dfs2(int, int, std::vector, int, int, std::vector); + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> g[i] + 1; + } + dfs1(1, 1, std::vector()); + cout << ans << endl; + return 0; +} + +void dfs1(int x, int y, std::vector s) { + if (x < 1 || x > n || y < 1 || y > n) return; + s.push_back(g[x][y] - 'A'); + if (x + y == n + 1) { + ans = (ans + dfs2(n, n, std::vector(), x, y, s)) % mod; + return; + } + dfs1(x + 1, y, s); + dfs1(x, y + 1, s); +} + +long long dfs2( + int x, + int y, + std::vector s, + int lx, + int ly, + std::vector t) { + if (x < lx || x > n || y < ly || y > n) return 0; + s.push_back(g[x][y] - 'A'); + long long res = 0; + if (x == lx && y == ly && s == t) return 1; + res += dfs2(x - 1, y, s, lx, ly, t); + res += dfs2(x, y - 1, s, lx, ly, t); + return res; +}