将2*n长度的字符串拆成两段,两段分别计算,开个map
在s1==s2前提下,
s1在前半段出现的从左往右出现的字符,s2一定在后半段从右往左出现
即正序s1前半段=逆序s2后半段,正序s2前半段=逆序s1后半段
typedef long long lxl;
map<pair<string,string>, lxl> cnt;
const int maxn = 50;
char s[maxn];
int main() {
freopen("b.in", "r", stdin);
freopen("b.out", "w", stdout);
int n;
cin>>n>>s;
for(int i = 0; i < (1 << n); i++) {
string s1 = "", s2 = "";
for(int j = 0; j < n; j++) {
if(i & (1 << j)) s1 += s[j];
else s2 += s[j];
}
cnt[{s1,s2}]++;
}
lxl sum = 0;
for(int i = 0; i < (1 << n); i++) {
string s1 = "", s2 = "";
for(int j = n - 1; j >= 0; j--) {
if(i & (1 << j)) s1 += s[j + n];
else s2 += s[j + n];
}
sum += cnt[{s1,s2}];
}
cout<<sum<<'
';
}