Problem:
Score : 800 points

Problem Statement

Given is a string S consisting of 0 and 1. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive):

Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are 0 and 1, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.

Constraints

1 \leq |S| \leq 300

0 \leq K \leq 10^9

S consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

S K

Output

Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive).

Sample Input 1

0101 1

Sample Output 1

4

Four strings, 0101, 0110, 1001, and 1010, can result.

Sample Input 2

01100110 2

Sample Output 2

14

Sample Input 3

1101010010101101110111100011011111011000111101110101010010101010101 20

Sample Output 3

113434815

Solution in Rust (1.42.0) (judge verdict: Accepted)

use proconio::{fastout, input};

use proconio::marker::Chars;
use std::cmp::{max, min};

#[fastout]
fn main() {
    const M: usize = 998244353;
    input! {
        s: Chars, k: usize,
    }
    let n = s.len();
    let k = min(k, s.len());
    let mut a = vec![0];
    for c in s {
        if c == '0' {
            a.push(0);
        }
        if c == '1' {
            if let Some(last) = a.last_mut() {
                *last += 1;
            }
        }
    }
    let mut h = vec![vec![vec![None; k + 1]; n]; a.len() + 1];
    fn f(
        i: usize,
        j: usize,
        k: usize,
        a: &Vec<usize>,
        h: &mut Vec<Vec<Vec<Option<usize>>>>,
    ) -> usize {
        if i == 0 {
            return 1;
        }
        if let Some(v) = h[i][j][k] {
            return v;
        }
        let mut s = 0;
        for l in 0..=min(k, a[i]) {
            s += f(i - 1, j + l, k - l, a, h);
            s %= M;
        }
        for l in 1..=j {
            s += f(i - 1, j - l, k, a, h);
            s %= M;
        }
        h[i][j][k] = Some(s);
        s
    }
    let ans = f(a.len() - 1, 0, k, &a, &mut h);
    println!("{}", ans);
}