Nun Heh Heh Aaaaaaaaaaa(动态规划,排列组合)

题目链接

Code

#include<bits/stdc++.h>
#define int long long
#define endl '\n' 
#define br putchar('\n') 
#define _x fixed << setprecision
#define debug(x) cout << "------" << x << "-----\n";
#define ok() cout << "Yes\n" 
#define gg() cout << "No\n" 
#define mem(a, b) memset(a, b, sizeof(a));
#define rep(i, a, b) for (int i = a;i <= b; ++i)
#define rrep(i, a, b) for(int i = a; i >= b; --i)
#define All(a) ((a.begin()), (a.end()))
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int mod = 998244353;
LL gcd(LL a, LL b) { return b ? gcd(b, a%b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL qmul(LL a, LL b, LL p) {
    a %= p; b %= p;
    LL ret = 0;
    LL tmp = a;
    while(b) {
        if( b & 1) {ret += tmp; if(ret > p ) ret -= p;}
        tmp <<= 1; if(tmp > p) tmp -= p;
        b >>= 1;
    }
    return ret;
}
LL qpow(LL a, LL b, LL p){
    LL Ans = 1;
    LL ret = a % p;
    while(b) {
    if(b & 1) Ans = qmul(Ans, ret, p);
        ret = qmul(ret, ret, p);
        b >>= 1;
    }
    return Ans;
}
signed main(){
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    IOS;
    int tt; cin >> tt;
    while (tt -- )
    {
        int ans = 0;
        string t = "nunhehheh", s;
        cin >> s;
        s = '0' + s;
        int len = s.size();
        vector<int> a(len+10, 0);
        for(int i = len; i; -- i) a[i] = a[i + 1] + (s[i] == 'a');
        vector<vector<int> > dp(len + 10, vector<int>(11, 0));
        // dp[i][j]表示s的前i位种出现t的1-j位的次数
        for(int i = 1; i <= len; ++i)
        {
            dp[i][1] = (dp[i - 1][1] + (s[i] == 'n')) % mod;
            dp[i][2] = (dp[i - 1][2] + dp[i - 1][1] * (s[i] == 'u')) % mod;
            dp[i][3] = (dp[i - 1][3] + dp[i - 1][2] * (s[i] == 'n')) % mod;
            dp[i][4] = (dp[i - 1][4] + dp[i - 1][3] * (s[i] == 'h')) % mod;
            dp[i][5] = (dp[i - 1][5] + dp[i - 1][4] * (s[i] == 'e')) % mod;
            dp[i][6] = (dp[i - 1][6] + dp[i - 1][5] * (s[i] == 'h')) % mod;
            dp[i][7] = (dp[i - 1][7] + dp[i - 1][6] * (s[i] == 'h')) % mod;
            dp[i][8] = (dp[i - 1][8] + dp[i - 1][7] * (s[i] == 'e')) % mod;
            dp[i][9] = (dp[i - 1][8] * (s[i] == 'h')) % mod;
            if(dp[i][9]) ans = (ans + (qpow(2, a[i + 1], mod) - 1) * dp[i][9]) % mod; 
        }
        cout << ans << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

W⁡angduoyu

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

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

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

打赏作者

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

抵扣说明:

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

余额充值