• 马拉车

    char str[N],s[N];
    int len[N]={0};
    int manachr(){
        s[0]='$';
        int n=1;
        for(int i=0;str[i];i++)s[n++]='#',s[n++]=str[i];
        s[n++]='#';s[n]='\0';
        int MAX=0,id=0,mix=0;
        for(int i=1;imix)mix=len[i]+i,id=i,MAX=max(MAX,len[i]);
        }
        for(int i=1;i
  • 最长回文子序列
    int dp[1005][1005];
    char str[N];
    // dp[i][j] 代表 str[i]到str[j] 中回文子序列的最大长度
    // str[i]==str[j] dp[i][j]=dp[i+1][j-1]+2;
    // str[i]!=str[j] dp[i][j]=max(dp[i][j-1],dp[i+1][j]);
    int main(){
        cin>>(str+1);
        int n=strlen(str+1);
        for(int i=n;i>=1;i--){
                dp[i][i]=1;
                for(int j=i+1;j<=n;j++){
                        if(str[i]==str[j])dp[i][j]=dp[i+1][j-1]+2;
                        else dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
                }
        }
        cout<