Nun Heh Heh Aaaaaaaaaaa HDU7131

题目链接:Problem - 7131

Problem Description

Vasily Tadokorov is a stringologist. He thinks a string is fragrant if it can be divided into two parts — nunhehheh as the prefix and a number of (excluding 0) a as the suffix. For example, nunhehhehaaaaaa is fragrant, but nunhehheh and nunhehhehoooaaa 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

#include<bits/stdc++.h>
using namespace std;
const int N = 998244353;

long long dp[15][100005];
long long num[100005];

long long power(long long a, long long n){
    if(n == 0){
        return 1;
    }
    long long temp = 1;
    while(n){
        if(n & 1){
            temp *= a;
            temp %= N;
        }
        a *= a;
        a %= N;
        n /= 2;
    }
    return temp;
}

int main(){
    ios::sync_with_stdio(false); 
    int k;
    string s;
    string t = "nunhehheh";
    cin >> k;
    while(k--){
        cin >> s;
        for(int i = 0; i < s.length() + 1; i++){
            dp[0][i] = 1;
            num[i] = 0;
        }
        for(int i = 0; i < t.length() + 1; i++){
            dp[i][0] = 0;
        }
        dp[0][0] = 1;
        for(int i = 1; i < t.length() + 1; i++){
            for(int l = 1; l < s.length() + 1; l++){
                dp[i][l] = dp[i][l - 1];
                if(t[i - 1] == s[l - 1]){
                    dp[i][l] += dp[i - 1][l - 1];
                    dp[i][l] %= N;
                }
            }
        } 
//        for(int i = 0; i < t.length() + 1; i++){
//            for(int l = 0; l < s.length() + 1; l++){
//                cout << dp[i][l] << " ";
//            }
//            cout << endl;
//        }
        long long ans = 0;
        long long a = 0;
        for(int l = s.length(); l >= 1; l--){
            if(s[l - 1] == 'a'){
                ans++;
            }
            if(s[l - 1] == 'h'){
                num[l] = power(2, ans) - 1;
                while(num[l] < 0){
                    num[l] += N;
                }
            }
        }
        long long sum = 0;
        for(int i = 1; i < s.length() + 1; i ++){
            if(s[i - 1] == 'h'){
                long long cnt = num[i] * ((dp[9][i] - a + N) % N);
                cnt %= N;
                sum += cnt;
                sum %= N;
                a = dp[9][i];
            }
        }
        cout << sum << endl;
        
    }
    return 0;
}
//n u n h e h h e h a h a a h a h a h a h a h a h a a h a a h a h a h a h h a

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值