1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <cstdio> #include <algorithm> #include <cstring> #define maxn 100010 #define mod 998244353 #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, r, l) for (int i = r; i >= l; i--) #define ll long long using namespace std; int read() { int p = 0, f = 1; char c = getchar(); while (c < 48 || c > 57) { if (c == '-') f = -1; c = getchar(); } while (c >= 48 && c <= 57) p = (p << 1) + (p << 3) + (c ^ 48), c = getchar(); return p * f; } ll F[maxn], rF[maxn]; char s[maxn]; ll inv(ll a, ll m) { if (a == 1) return 1; return inv(m % a, m) * (m - m / a) % m; } int main() { int t = read(); F[0] = rF[0] = 1; rep(i, 1, maxn - 1) { F[i] = F[i - 1] * i % mod; rF[i] = rF[i - 1] * inv(i, mod) % mod; } while (t--) { int n = read(); scanf("%s", s + 1); int cg = 0, c1 = 0, c0 = 0; rep(i, 1, n) { if (s[i] == '0') c0++; else if (i + 1 <= n && s[i + 1] == '1') cg++, i++; else c1++; } int ans = F[cg + c0] * rF[c0] % mod * rF[cg] % mod; printf("%d\n", ans); } return 0; }
|