//第二题---更好理解
int count_seq(string str, int low, int high) {
int result = 0;
if (high - low == 0) {
return 1;
}
if (high - low == 1) {
if (str[high] == str[low])
return 3;
else
return 2;
}
if (str[low] == str[high]) {
result = count_seq(str, low + 1, high) + count_seq(str, low, high - 1) + 1;
}
else {
result = count_seq(str, low + 1, high) + count_seq(str, low, high - 1) - count_seq(str, low + 1, high - 1);
}
return result;
}
int main() {
string str = "ABA";
cout << count_seq(str, 0, str.length() - 1) << endl;
}