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 C++ (GCC 9.2.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
const int MAX = 303;
using M = Mint<int, 998244353>;

M dp[MAX][MAX][MAX]={};
M ac[MAX][MAX]={};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  string s;
  cin>>s;
  int k;
  cin>>k;

  chmin(k,MAX-1);

  while(!s.empty() and s.front()=='1') s.erase(s.begin());
  while(!s.empty() and s.back() =='0') s.erase(--s.end());
  if(s.empty()) drop(1);

  vector<int> vs;
  for(char c:s){
    if(c=='0') vs.emplace_back(0);
    if(c=='1') vs.back()++;
  }

  int n=vs.size();
  vector<int> sm(n+1,0);
  for(int i=0;i<n;i++)
    sm[i+1]=sm[i]+vs[i];

  for(int x=0;x<MAX;x++) dp[0][x][0]=M(1);

  for(int i=0;i<n;i++){
    for(int j=sm[i];j<MAX;j++){
      int need=sm[i+1]-j;

      for(int d=0;d<vs[i];d++){
        for(int c=0;c<MAX;c++)
          if(need<=d and j+d<MAX and c+(vs[i]-d)<MAX)
            dp[i+1][j+d][c+(vs[i]-d)]+=dp[i][j][c];
      }
    }

    for(int j=0;j<MAX;j++)
      for(int c=0;c<MAX;c++)
        ac[j][c]=M(0);

    for(int j=sm[i];j+1<MAX;j++)
      for(int c=0;c<MAX;c++)
        ac[j+1][c]=ac[j][c]+dp[i][j][c];

    for(int j=sm[i];j+1<MAX;j++)
      for(int c=0;c<MAX;c++)
        dp[i+1][j][c]+=ac[max(j-vs[i]+1,0)][c];
  }



  M ans{0};
  for(int c=0;c<=k;c++)
    ans+=dp[n][sm[n]][c];
  cout<<ans<<newl;
  return 0;
}