From 1143dee5856dd6a8f1ef18667c3c0a741657bf95 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 26 Dec 2021 19:53:31 +0800 Subject: [PATCH] =?UTF-8?q?#1200.=20[2016NOIP=E7=A6=8F=E5=BB=BA=E5=A4=8F?= =?UTF-8?q?=E4=BB=A4=E8=90=A5]=E8=BF=B7=E5=AE=AB=20[40pts]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/46119 --- S2OJ/1200/1200.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 S2OJ/1200/1200.cpp 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; +}