题解 CF1545B AquaMoon and Chess
题目链接
题目描述
给一个长为
题解
可以注意到一个非常明显的特点:关于一对相邻的
因此我们可以将棋盘上所有的
而对于相邻的奇数个
由此可见,在棋盘上,
设
实现
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
using namespace std;
bool Handsome;
const int M=1e5+5,P=998244353;
int n,F[M],INV[M];
char s[M];
int FAST(int x,int y){
int res=1;
for(;y;y>>=1){
if(y&1)res=1ll*res*x%P;
x=1ll*x*x%P;
}
return res;
}
void init(){
F[0]=INV[0]=1;
rep(i,1,1e5)F[i]=1ll*F[i-1]*i%P;
INV[100000]=FAST(F[100000],P-2);
drep(i,99999,1)INV[i]=1ll*INV[i+1]*(i+1)%P;
}
int C(int x,int y){return 1ll*F[x]*INV[y]%P*INV[x-y]%P;}
void solve(){
scanf("%d%s",&n,s+1);
int p=1,a=0,b=0;
for(;p<=n;++p){
if(s[p]=='1' && s[p+1]=='1'){
++a;++p;
}
else if(s[p]=='0')++b;
}
printf("%d\n",C(a+b,b));
}
bool Most;
int main(){
// printf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0);
init();
int t;scanf("%d",&t);
while(t--)solve();
return 0;
}