比赛 20241021 评测结果 AAAAAAAAAA
题目名称 体育课 最终得分 100
用户昵称 darkMoon 运行时间 0.317 s
代码语言 C++ 内存使用 5.79 MiB
提交时间 2024-10-21 09:01:20
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("sportk.in", "r", stdin);
auto OUT = freopen("sportk.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 1e5 + 5, MOD = 998244353;
int n = mread(), m = mread(), f[N][15], fac[N], ifac[N];
char s[N];
int ksm(int x, int k){
    int ans = 1, now = x;
    while(k){
        if(k & 1){
            ans = ans * now % MOD;
        }
        now = now * now % MOD;
        k >>= 1;
    }
    return ans;
}
int C(int n, int m){
    if(n < m){
        return 0;
    }
    return fac[n] * ifac[n - m] % MOD * ifac[m] % MOD;
}
signed main(){
    fac[0] = ifac[0] = 1;
    for(int i = 1; i < N; i ++){
        fac[i] = fac[i - 1] * i % MOD;
        ifac[i] = ksm(fac[i], MOD - 2);
    }
    scanf("%s", s + 1);
    int ans = 0;
    for(int m2 = 1; m2 <= m; m2 ++){
        f[0][0] = 0;
        for(int i = 1; i <= n; i ++){
            for(int j = 0; j <= m; j ++){
                f[i][j] = 0;
            }
            if(s[i] == '1'){
                f[i][1] = 1;
            }
            for(int j = 1; j <= m; j ++){
                f[i][j] = (f[i][j] + f[i - 1][j] + f[i - 1][j - 1]) % MOD;
            }
            f[i - 1][0] = 1;
            if(s[i] == '1'){
                for(int j = 1; j <= m2; j ++){
                    (ans += ksm(2, j - 1) * C(n - i, j - 1) % MOD * f[i - 1][m2 - j] % MOD) %= MOD;
                }
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}