讨论/技术交流/测试无问题,提交出错/
测试无问题,提交出错

#define MAX(a,b) (a)>(b)?(a):(b)
int g_state[1000][1000] = {0};
int strHandle(char *str,int begin,int end)
{
if(begin == end)
return 1;
if(begin > end)
return 0;

if(!g_state[begin+1][end-1])
    g_state[begin+1][end-1] = strHandle(str,begin+1,end-1);
if(!g_state[begin+1][end])
    g_state[begin+1][end] = strHandle(str,begin+1,end);
if(!g_state[begin][end-1])
    g_state[begin][end-1] = strHandle(str,begin,end-1);

if(str[begin] == str[end])
    return(g_state[begin+1][end-1] + 2);
else
    return MAX(g_state[begin+1][end],g_state[begin][end-1]);    

}

int longestPalindromeSubseq(char * s){
int len = 0;
int ret = 0;

len = strlen(s);
ret = strHandle(s,0,len-1);
return ret;
  • }
共 1 个回复

输入:
"cbbd"
输出:
3
预期:
2
516 最长回文子序列 问题