PAT T1025 Keep at Most 100 Characters

删除字符的镜像问题,状态转移方程一样~

#include
using namespace std;
const int maxn=1014;
const int mod=1e9+7;
string s;
long long dp[maxn][maxn];
int main () {
    cin>>s;
    fill (dp[0],dp[0]+maxn,1);
    int t=max(0,(int)(s.length()-100));
    for (int i=1;i) {
        for (int j=i;j<=s.length();j++) {
            dp[i][j]=dp[i][j-1]%mod+dp[i-1][j-1]%mod;
            dp[i][j]%=mod;
            for (int k=j-1;j-k<=i;k--) {
                if (s[k-1]==s[j-1]) {
                    dp[i][j]-=dp[i-(j-k)][k-1];
                    break;
                }
            }
        }
    }
    long long sum=0;
    for (int i=t;i) {
        sum+=dp[i][s.length()];
        sum%=mod;
    }
    printf ("%lld",sum);
    return 0;
} 

 

你可能感兴趣的:(PAT T1025 Keep at Most 100 Characters)