字符串(string)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define inf 1e9
#define pii pair<int, int>
const ll mod=998244353;
void write(ll x){
    if(x<0) x=-x,putchar('-');
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
void add(ll &x, ll y){
    x+=y;
    if(x>=mod) x-=mod;
}
ll n,ans;
char ch[5005];
ll f[5005][27][27];
int main(){
	freopen("string.in", "r", stdin);
	freopen("string.out", "w", stdout);
    scanf("%lld%s",&n,ch+1);
    f[0][0][0]=1;
    for(ll i=1;i<=n;i++)
        for(ll j=1;j<=26;j++){
            if(ch[i]!='?'&&ch[i]-'a'+1!=j) continue;
            for(ll j2=0;j2<=26;j2++)
                for(ll j1=0;j1<=26;j1++){
                    if(j==j1||j==j2) continue;
                    add(f[i][j1][j],f[i-1][j2][j1]);
                }
        }
    for(ll j2=0;j2<=26;j2++) for(ll j1=0;j1<=26;j1++) add(ans,f[n][j2][j1]);
    write(ans);
    return 0;
}

人民能看懂的code才是好code....

0 条评论

目前还没有评论...