1 条题解

  • 0
    @ 2026-10-15 17:42:45

    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<cstring>
    using namespace std;
    const int N =51;
    int f[N][N];
    int main()
    {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;cin>>s;int n=s.size();

    memset(f,0x3f,sizeof f);
    for(int i=0;i<n;i++) f[i][i]=1;

    for(int len=2;len<=n;len++)
    for(int i=0;i+len-1<n;i++)
    {
    int j=i+len-1;
    for(int k=i;k<j;k++)
    f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);

    if(s[i]==s[j])
    f[i][j]=min({f[i][j],f[i+1][j],f[i][j-1]});

    }

    cout<<f[0][n-1];

    return 0;
    }

  • 1

古籍展架优化计划 pta202505T4

信息

ID
2924
难度
9
分类
(无)
标签
递交数
14
已通过
3
通过率
21%
上传者