美文网首页
2018-08-06

2018-08-06

作者: lemonline丶 | 来源:发表于2018-08-06 15:12 被阅读0次
print hello
#include <iostream>
#include <vector>
using namespace std;

int hwc(string str){
    int len=str.length();
    vector<vector<int> > d(len,vector<int>(len));

    for(int j=0;j<len;j++){
        d[j][j]=1;
        for(int i=j-1;i>=0;i--){
            d[i][j]=d[i+1][j]+d[i][j-1]-d[i+1][j-1];
            if(str[i]==str[j])
                d[i][j]+=1+d[i+1][j-1];
        }
    }
    return d[0][len-1];
}

int main()
{
    string s;
    int n;
    while(cin>>s){
        n=hwc(s);
        cout<<n<<endl;
    }
    return 0;
}

相关文章

网友评论

      本文标题:2018-08-06

      本文链接:https://www.haomeiwen.com/subject/jlcgvftx.html