rt, 68pts,题目链接
#include <bits/stdc++.h>
using namespace std;
const int dx [] = {0, 1}, dy [] = {1, 0};
int n, ans;
char g [20] [20];
char str [40];
unordered_set <string> uset;
void dfs (int x, int y, int size) {
str [size] = g [x] [y];
if (x + 1 == n && y + 1 == n) {
uset. insert (str);
return ;
}
for (int i = 0 ; i < 2; i ++) {
int x2 = dx [i] + x;
int y2 = dy [i] + y;
if (x2 >= n || y2 >= n) {
continue;
}
if (x + y >= n && str [2 * n - size - 2] != g [x] [y]) continue;
dfs (x2, y2, size + 1);
}
}
int main () {
cin >> n;
for (int i = 0 ; i < n ; i ++)
for (int j = 0 ; j < n ; j ++) {
cin >> g [i] [j];
}
dfs (0, 0, 0);
cout << uset. size ();
return 0;
}