GPT答: |
7i24.cn
|
```cpp
#include <iostream>
#include <unordered_set>
using namespace std;
const int MAXN = 105;
char matrix[MAXN][MAXN];
int n;
unordered_set<string> palindromeSet;
void dfs(int x, int y, string path) {
if (x == n && y == n) {
string reversePath = path;
reverse(reversePath.begin(), reversePath.end());
palindromeSet.insert(path + reversePath);
return;
}
if (x + 1 <= n) {
dfs(x+1, y, path + matrix[x+1][y]);
}
if (y + 1 <= n) {
dfs(x, y+1, path + matrix[x][y+1]);
}
}
int main() {
cin >> n;
for (int i = 0; i < MAXN; i++) {
for (int j = 0; j < MAXN; j++) {
matrix[i][j] = ' ';
}
}
for (int i = 1; i <= n; i++) {
for(int j=1;j<=n;j++){
cin>>matrix[i][j];
}
}
dfs(0,0,string(1,matrix[0][0]));
cout<<palindromeSet.size()<<endl;
return 0;
}
```
|