2021中国大学生程序设计竞赛(CCPC)- 网络选拔赛(重赛)1006(快速幂+dp+后缀和)

Nun Heh Heh Aaaaaaaaaaa

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1873    Accepted Submission(s): 1031


 

Problem Description
Vasily Tadokorov is a stringologist. He thinks a string is fragrant if it can be divided into two parts — 𝚗𝚞𝚗𝚑𝚎𝚑𝚑𝚎𝚑 as the prefix and a number of (excluding 0) 𝚊 as the suffix. For example, 𝚗𝚞𝚗𝚑𝚎𝚑𝚑𝚎𝚑𝚊𝚊𝚊𝚊𝚊𝚊 is fragrant, but 𝚗𝚞𝚗𝚑𝚎𝚑𝚑𝚎𝚑 and 𝚗𝚞𝚗𝚑𝚎𝚑𝚑𝚎𝚑𝚘𝚘𝚘𝚊𝚊𝚊 are not fragrant.

Today Vasily Tadokorov has some strings consisting of lowercase English letters. For each string, he wants to know how many subsequences of this string are fragrant. A string a is a subsequence of a string b if a can be obtained from b by deletion of several (including 0) characters.
 

Input
The first line contains an integer T (1≤T≤1000), denoting the number of strings.

Each of the next T lines contains a string S (1≤|S|≤105) consisting of lowercase English letters.

The total length of the strings in the input will not exceed 106.
 

Output
For each of the given T strings, output the answer modulo 998244353.
 

Sample Input
 
 
2 nunhehhehahaahahahahahahaahaahahahahha nunhehhehhehhahaahahahaahaahahaaaahaa
 

Sample Output
 
 
114514
1919810
const int mod=998244353;
int t;
ll dp[11][10100];
//dp[i][j]是s的前j位中ss中1-i字符串出现的次数
int main(){
    cin>>t;
    while (t--) {
        ll ans=0;
        string ss="nunhehheh";
        string s;
        cin>>s;
        s="0"+s;
        int len=s.size();
        int a[100010];
        mms(a,0);
        for(int i=len;i>=1;i--)
            a[i]=a[i+1]+(s[i]=='a');
        for(int i=1;i<=len;i++){
            dp[1][i]=(dp[1][i-1]+(s[i]=='n'))%mod;
                        dp[2][i]=(dp[2][i-1]+dp[1][i-1]*(s[i]=='u'))%mod;
                        dp[3][i]=(dp[3][i-1]+dp[2][i-1]*(s[i]=='n'))%mod;
                        dp[4][i]=(dp[4][i-1]+dp[3][i-1]*(s[i]=='h'))%mod;
                        dp[5][i]=(dp[5][i-1]+dp[4][i-1]*(s[i]=='e'))%mod;
                        dp[6][i]=(dp[6][i-1]+dp[5][i-1]*(s[i]=='h'))%mod;
                        dp[7][i]=(dp[7][i-1]+dp[6][i-1]*(s[i]=='h'))%mod;
                        dp[8][i]=(dp[8][i-1]+dp[7][i-1]*(s[i]=='e'))%mod;
                        dp[9][i]=(dp[8][i-1]*(s[i]=='h'))%mod;
                        if(dp[9][i])
                            ans=ans%mod+(dp[9][i]*(pows(2,(a[i+1]),mod)-1))%mod;
                        ans%=mod;
        }
        cout<<ans<<endl;
    }
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值