mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-12-16 04:03:01 +00:00
fix(P3102): 修正动态规划计算逻辑和输出格式
将加法操作改为乘法操作以正确计算组合数,并简化输出结果的格式
This commit is contained in:
parent
3c29bca56e
commit
9f190cb94c
@ -34,12 +34,12 @@ static inline ll dfs(const ll l,const ll r){
|
||||
for(ll j=0;j<clen;j++){
|
||||
if(s[l+j]!=s[i+j])goto nxt1;
|
||||
}
|
||||
dp[l][r]=((i-l>r-i+1?dfs(l, i-1):dfs(i, r))+dp[l][r])%p;
|
||||
dp[l][r]=(dfs(l, i-1)*dfs(i, r)%p+dp[l][r])%p;
|
||||
nxt1:;
|
||||
for(ll j=0;j<clen;j++){
|
||||
if(s[i-1-j]!=s[r-j])goto nxt2;
|
||||
}
|
||||
dp[l][r]=((i-l>r-i+1?dfs(l, i-1):dfs(i, r))+dp[l][r])%p;
|
||||
dp[l][r]=(dfs(l, i-1)*dfs(i, r)%p+dp[l][r])%p;
|
||||
nxt2:;
|
||||
}
|
||||
return dp[l][r];
|
||||
@ -53,5 +53,5 @@ int main(){
|
||||
n=s.size();
|
||||
s=' '+s;
|
||||
dp.resize(n+1,std::vector<ll>(n+1));
|
||||
std::cout<<(dfs(1,n)-1+p)%p<<"\n";
|
||||
std::cout<<dfs(1,n)-1<<"\n";
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user