# codeforces 1546D - AquaMoon and Chess 题解

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 998244353;
ll t;
ll n;
ll cnt0;
ll cnt1;
ll g;
ll ans;
string s;
ll f[100010];
ll fin[100010];
ll qpow(ll x, ll y) {
ll ret = 1ll;
while (y) {
if (y & 1) ret = (ret * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return ret % mod;
}
ll inv(ll x) {
return qpow(x, mod - 2);
}
void init() {
f[0] = fin[0] = 1ll;
for (ll i = 1; i <= 100000; i++) {
f[i] = (i * f[i - 1]) % mod;
fin[i] = (fin[i - 1] * inv(i)) % mod;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
init();
cin >> t;
while (t--) {
cnt0 = cnt1 = g = 0;
cin >> n;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
if (i == s.length() - 1) {
cnt1 ++;
g += cnt1 / 2;
}
else {
cnt1 ++;
}
}
else {
cnt0 ++;
g += cnt1 / 2;
cnt1 = 0;
}
}
ans = ((f[cnt0 + g] * fin[g])  % mod * fin[cnt0]) % mod;
cout << ans << "\n";
}
return 0;
}

posted @ 2021-07-12 20:38  Leins  阅读(56)  评论(0编辑  收藏  举报