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 <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

#define P 998244353

int dif2(int a, int b){return a<b?b-a:a-b;}

char s[301];
int a[602];
int b[602];
int d[602][602][804];
int main(void){
	int n=nextstr(s);
	int K=nextint();
	int m=0;
	for(int i=0; i<n; i++){
		if(s[i]=='0'){
			m++;
		}else{
			a[m]++;
		}
	}
	m++;
	b[m-1]=a[m-1];
	for(int i=m-2; i>=0; i--){
		b[i]=b[i+1]+a[i];
	}
	d[m][0][0]=1;
	for(int i=m-1; i>=0; i--){
		for(int j=0; j<=b[i]; j++){
			for(int k=0; k<=b[i]*2; k++){
				for(int l=0; l<=j; l++){
					int p=k-dif2(a[i],l);
					if(p>=0){
						d[i][j][k]+=d[i+1][j-l][p];
						d[i][j][k]%=P;
					}
				}
			}
		}
	}
	long ans=0;
	for(int k=K<b[0]?K*2:b[0]*2; k>=0; k--){
		ans+=d[0][n-m+1][k];
	}
	ans%=P;
	printf("%ld\n", ans);
}