description: You are given a binary string (i. e. a string consisting of characters 0 and/or 1) s of length n. You can perform the following operation with the string s at most once: choose a substring (a contiguous subsequence) of s having exactly k characters 1 in it, and shuffle it (reorder the characters in the substring as you wish).
  
  Calculate the number of different strings which can be obtained from s by performing this operation at most once.
  
  Input
  
  The first line contains two integers n and k (2 ≤ n ≤ 5000; 0 ≤ k ≤ n).
  
  The second line contains the string s of length n, consisting of characters 0 and/or 1.
  
  Output
  
  Print one integer — the number of different strings which can be obtained from s by performing the described operation at most once. Since the answer can be large, output it modulo 998244353.
  
  Examples
  
  Input
  
  
  7 2
  1100110
  
  
  Output
  
  
  16
  
  
  Input
  
  
  5 0
  10010
  
  
  Output
  
  
  1
  
  
  Input
  
  
  8 1
  10001000
  
  
  Output
  
  
  10
  
  
  Input
  
  
  10 8
  0010011000
  
  
  Output
  
  
  1
  
  Note
  
  Some strings you can obtain in the first example:
  
    * to obtain 0110110, you can take the substring from the 1-st character to the 4-th character, which is 1100, and reorder its characters to get 0110; 
    * to obtain 1111000, you can take the substring from the 3-rd character to the 7-th character, which is 00110, and reorder its characters to get 11000; 
    * to obtain 1100101, you can take the substring from the 5-th character to the 7-th character, which is 110, and reorder its characters to get 101. 
  
  
  
  In the second example, k = 0 so you can only choose the substrings consisting only of 0 characters. Reordering them doesn't change the string at all, so the only string you can obtain is 10010.
solution: #include <bits/stdc++.h>
  using namespace std;
  const int N = 5e3 + 5;
  const int MOD = 998244353;
  int ADD(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
  int TIME(int x, int y) { return (int)(1ll * x * y % MOD); }
  int ksm(int x, int k = MOD - 2) {
    int res = 1;
    for (; k; k >>= 1, x = TIME(x, x))
      if (k & 1) res = TIME(res, x);
    return res;
  }
  int n, m = 0, k, a[N], b[N];
  int fact[N], ifact[N];
  int C(int n, int m) {
    if (n < 0 || m < 0 || n - m < 0) return 0;
    return TIME(fact[n], TIME(ifact[m], ifact[n - m]));
  }
  struct Seg {
    int l, r, data;
  };
  bool operator<(Seg a, Seg b) { return a.l > b.l; }
  priority_queue<Seg> q;
  int main() {
    cin >> n >> k;
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = TIME(fact[i - 1], i);
    ifact[n] = ksm(fact[n]);
    for (int i = n; i >= 1; --i) ifact[i - 1] = TIME(ifact[i], i);
    a[0] = a[n + 1] = 1;
    for (int i = 1; i <= n; ++i) scanf("%1d", &a[i]), b[i] = b[i - 1] + a[i];
    for (int i = 1; i <= n; ++i) {
      for (int j = i, cnt = a[i]; j <= n; ++j, cnt += a[j])
        if (cnt == k && a[i - 1] == 1 && a[j + 1] == 1)
          q.push((Seg){i, j, C(j - i + 1, k)});
    }
    if (!k || q.empty()) return printf("1\n"), 0;
    while (q.size() > 1) {
      Seg f = q.top();
      q.pop();
      Seg g = q.top();
      q.pop();
      Seg h = (Seg){
          f.l, g.r,
          ADD(ADD(f.data, g.data), MOD - C(f.r - g.l + 1, b[f.r] - b[g.l - 1]))};
      q.push(h);
    }
    return printf("%d\n", q.top().data), 0;
  }
  