标签:character print har most long const 状态转移方程 i++ std
删除字符的镜像问题,状态转移方程一样~
#include<bits/stdc++.h> 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<s.length();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<s.length();i++) { sum+=dp[i][s.length()]; sum%=mod; } printf ("%lld",sum); return 0; }
PAT T1025 Keep at Most 100 Characters
标签:character print har most long const 状态转移方程 i++ std
原文地址:https://www.cnblogs.com/zhanglichen/p/12309699.html