令
f
s
f_s
fs表示走到状态
s
s
s的期望步数
那么有
s
=
∅
,
f
s
=
0
s=\empty,f_s=0
s=∅,fs=0
e
l
s
e
,
f
s
=
1
+
∑
i
f
s
⊕
i
p
i
else ,f_s=1+\sum_{i}f_{s\oplus i}p_i
else,fs=1+∑ifs⊕ipi
这是
f
w
t
fwt
fwt的形式
设
f
f
f为
f
s
f_s
fs的集合幂级数
设
g
=
∑
i
p
i
x
2
i
g=\sum_{i}p_ix^{2^i}
g=∑ipix2i
那么有
f
=
∑
s
x
s
+
f
∗
g
+
r
x
∅
f=\sum_{s}x^s+f*g+rx^{\empty}
f=s∑xs+f∗g+rx∅
r
r
r是由于
f
∅
f_{\empty}
f∅而设的一个未知量
f
(
1
−
g
)
=
∑
s
x
s
+
r
x
∅
f(1-g)=\sum_{s}x^s+rx^{\empty}
f(1−g)=s∑xs+rx∅
f
w
t
fwt
fwt后有
f
^
(
1
−
g
^
)
=
∑
s
∑
T
(
−
1
)
∣
S
∩
T
∣
x
s
+
∑
s
r
x
s
\hat f(1-\hat g)=\sum_{s}\sum_{T}(-1)^{|S\cap T|}x^s+\sum_{s}rx^s
f^(1−g^)=s∑T∑(−1)∣S∩T∣xs+s∑rxs
对于
s
=
∅
s=\empty
s=∅,由于
g
^
s
=
∑
i
p
i
=
1
\hat g_{s}=\sum_{i}p_i=1
g^s=∑ipi=1
左边为0
又由于有
1
2
n
∑
T
(
−
1
)
∣
S
∩
T
∣
=
[
s
=
∅
]
\frac{1}{2^n}\sum_{T}(-1)^{|S\cap T|}=[s=\empty]
2n1∑T(−1)∣S∩T∣=[s=∅]
所以
r
=
−
2
n
r=-2^n
r=−2n
对于
s
≠
∅
s\not=\empty
s=∅
那么
f
^
s
=
−
2
n
1
−
g
^
s
\hat f_s=\frac{-2^n}{1-\hat g_s}
f^s=1−g^s−2n
由于
f s = 1 2 n ∑ T ( − 1 ) ∣ S ∩ T ∣ f ^ T f_s=\frac{1}{2^n}\sum_{T}(-1)^{|S\cap T|}\hat f_T fs=2n1T∑(−1)∣S∩T∣f^T
= f ^ ∅ 2 n − ∑ T ≠ ∅ ( − 1 ) ∣ S ∩ T ∣ 1 1 − g ^ T =\frac{\hat f_{\empty}}{2^n}-\sum_{T\not =\empty}(-1)^{|S\cap T|}\frac{1}{1-\hat g_T} =2nf^∅−T=∅∑(−1)∣S∩T∣1−g^T1
对于 S = ∅ S=\empty S=∅
那么 f s = 0 = f ^ ∅ 2 n − ∑ T ≠ ∅ 1 1 − g ^ T f_s=0=\frac{\hat f_{\empty}}{2^n}-\sum_{T\not =\empty}\frac{1}{1-\hat g_T} fs=0=2nf^∅−T=∅∑1−g^T1
那么 f S = ∑ T ≠ ∅ ( 1 − ( − 1 ) ∣ S ∩ T ∣ ) 1 1 − g ^ T = ∑ T ≠ ∅ [ ∣ S ∩ T ∣ & 1 ] 2 1 − g ^ T f_S=\sum_{T\not=\empty}(1-(-1)^{|S\cap T|})\frac{1}{1-\hat g_T}\\=\sum_{T\not =\empty}[{|S\cap T|}\&1]\frac{2}{1-\hat g_T} fS=T=∅∑(1−(−1)∣S∩T∣)1−g^T1=T=∅∑[∣S∩T∣&1]1−g^T2
又 g ^ T = ∑ i ∉ T p i − ∑ i ∈ T p i \hat g_T=\sum_{i\notin T}p_i-\sum_{i\in T}p_i g^T=∑i∈/Tpi−∑i∈Tpi
f S = ∑ T ≠ ∅ [ ∣ S ∩ T ∣ & 1 ] 1 ∑ i ∈ T p i f_S=\sum_{T\not =\empty}[{|S\cap T|}\&1]\frac{1}{\sum_{i\in T}p_i} fS=T=∅∑[∣S∩T∣&1]∑i∈Tpi1
由于
p
p
p的值很小
考虑
d
p
dp
dp
f
[
i
]
[
j
]
[
0
/
1
]
f[i][j][0/1]
f[i][j][0/1]表示前
i
i
i个,概率之和为
j
j
j,与
S
S
S交集为奇偶的方案
最后加起来就完了
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ob==ib)?EOF:*ib++;
}
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define ll long long
#define re register
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define cs const
#define bg begin
template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int mod=998244353;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline void Dec(int &a,int b){(a-=b)<0?(a+=mod):0;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline void Mul(int &a,int b){a=1ll*a*b%mod;}
inline int ksm(int a,int b,int res=1){
for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;
}
inline int Inv(int x){return ksm(x,mod-2);}
cs int N=105,M=50005;
int f[N][M][2];
int n,s[N],p[N],inv[M],P;
inline void init(){
inv[0]=inv[1]=1;
for(int i=2;i<M;i++)inv[i]=mul(mod-mod/i,inv[mod%i]);
}
int main(){
n=read(),init();
for(int i=1;i<=n;i++)s[i]=read();
for(int i=1;i<=n;i++)p[i]=read();
f[0][0][0]=1;
for(int i=1;i<=n;i++){
P+=p[i];
for(int j=0;j<=P;j++)
for(int k=0;k<=1;k++){
Add(f[i][j][k],f[i-1][j][k]);
if(j>=p[i])Add(f[i][j][k^s[i]],f[i-1][j-p[i]][k]);
}
}
int res=0;
for(int i=1;i<=P;i++)
Add(res,mul(f[n][i][1],mul(P,inv[i])));
cout<<res;
}