//第二题---更好理解 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; }
点赞 评论

相关推荐

06-15 20:57
已编辑
门头沟学院 Java
CARLJOSEPH...:年轻人有傲气很正常,但是建议工作前洗净傲气。 说实在的,什么奖学金什么奖项的都很一般。尊重你的老师,在有时间的时候去上课,真遇到走不开的事,请态度端正地向你的老师说明情况,请求请假。我相信任何一个有师德的老师都会允许的(我的老师就是这样)。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务