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;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

ll N,K;
string S;
ll dp[303][303][303];
vector<ll> A;
ll cnt[303];

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

  cin>>S>>K;
  N=S.size();
  ll T=1;
  rep(i,N){
    if(S[i]=='1'){
      ll sum=0;
      repl(j,i,N)if(S[j]=='0')sum++;
      A.push_back(sum+1);
    }else T++;
  }
  dp[T][0][0]=1;
  ll M=A.size();
  rep(i,M)cnt[A[i]]++;
  for(ll i=T;i>0;i--){
    rep(j,M+1)rep(k,M+1){
      if(dp[i][j][k]==0)continue;
      repl(x,1,M+1-j){
        if(j+x>M)break;
        if(A[j+x-1]>i)break;
        (dp[i-1][j+x][k+max(0LL,x-cnt[i])]+=dp[i][j][k])%=mod;
      }
      (dp[i-1][j][k]+=dp[i][j][k])%=mod;
    }
  }
  ll res=0;
  rep(k,min(M+1,K+1)){
    (res+=dp[0][M][k])%=mod;
  }
  cout<<res<<endl;

  return 0;
}