# 做法

$g\left[i\right]=\left(w1+w2+w3+w4{\right)}^{i}-\sum _{j=1}^{i}W\left(j,0,0\right)\ast g\left[i-j\right]$$g[i]=(w1+w2+w3+w4)^i-\sum_{j=1}^iW(j,0,0)*g[i-j]$

$d=\sum _{i=0}^{n}\sum _{\left(x,y\right)}W\left(i,x,y\right)\ast g\left[n-i\right]$$d=\sum_{i=0}^n\sum_{(x,y)}W(i,x,y)*g[n-i]$

$R$$R$的计算也可以容斥：
$R\left(i,x,y\right)=W\left(i,x,y\right)-\sum _{j=1}^{i}W\left(j,0,0\right)\ast R\left(i-j,x,y\right)$$R(i,x,y)=W(i,x,y)-\sum_{j=1}^iW(j,0,0)*R(i-j,x,y)$

$S\left(i,x,y\right)=\sum _{j=1}^{i}W\left(j,x,y\right)\ast R\left(i-j,-x,-y\right)$$S(i,x,y)=\sum_{j=1}^iW(j,x,y)*R(i-j,-x,-y)$

$F\left(i,x,y\right)+=\sum _{j=1}^{i}g\left[j\right]\ast W\left(i-j,x,y\right)$$F(i,x,y)+=\sum_{j=1}^ig[j]*W(i-j,x,y)$

$F\left(i,x,y\right)-=\sum _{j=1}^{i}g\left[j\right]\ast S\left(i-j,-x,-y\right)$$F(i,x,y)-=\sum_{j=1}^ig[j]*S(i-j,-x,-y)$

$F\left(i,x,y\right)-=\sum _{j=1}^{i}F\left(j,x,y\right)\ast \left(W\left(i-j,0,0\right)-S\left(i-j,-x,-y\right)\right)$$F(i,x,y)-=\sum_{j=1}^iF(j,x,y)*(W(i-j,0,0)-S(i-j,-x,-y))$

$d2=\sum _{i=0}^{n}\sum _{\left(a,b\right)}\sum _{\left(x,y\right)}F\left(i,a,b\right)\ast W\left(n-i,x,y\right)$$d2=\sum_{i=0}^n\sum_{(a,b)}\sum_{(x,y)}F(i,a,b)*W(n-i,x,y)$

#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=220+10,mo=998244353;
int w[5],dx[5]={0,0,0,1,-1},dy[5]={0,-1,1,0,0};
int p1[maxn][maxn][maxn],p2[maxn][maxn][maxn],p3[maxn][maxn][maxn],p4[maxn][maxn][maxn];
int g[maxn];
int i,j,k,l,r,s,t,n,m,x,y,ans,all,d,d2;
int &W(int n,int x,int y){ return p1[x+105][y+105][n]; }
int &F(int n,int x,int y){ return p2[x+105][y+105][n]; }
int &S(int n,int x,int y){ return p3[x+105][y+105][n]; }
int &R(int n,int x,int y){ return p4[x+105][y+105][n]; }
int abs(int x){
return x<0?-x:x;
}
int main(){
scanf("%d",&n);
fo(i,1,4) scanf("%d",&w[i]);
W(0,0,0)=1;
fo(i,1,n)
fo(x,-n,n)
fo(y,-n,n)
if (abs(x)+abs(y)<=i)
fo(k,1,4)
(W(i,x,y)+=(ll)w[k]*W(i-1,x+dx[k],y+dy[k])%mo)%=mo;
g[0]=1;
all=w[1]+w[2]+w[3]+w[4];
t=1;
fo(i,1,n){
t=(ll)t*all%mo;
g[i]=t;
fo(j,1,i) (g[i]-=(ll)W(j,0,0)*g[i-j]%mo)%=mo;
}
fo(i,1,n)
fo(x,-n,n)
fo(y,-n,n)
if (abs(x)+abs(y)<=i){
R(i,x,y)=W(i,x,y);
fo(j,1,i-abs(x)-abs(y))
(R(i,x,y)-=(ll)W(j,0,0)*R(i-j,x,y)%mo)%=mo;
}
fo(i,1,n)
fo(x,-n,n)
fo(y,-n,n)
if (abs(x)+abs(y)<=i){
fo(j,max(abs(x)+abs(y),1),i-abs(x)-abs(y))
(S(i,x,y)+=(ll)W(j,x,y)*R(i-j,-x,-y)%mo)%=mo;
}
fo(i,1,n)
fo(x,-n,n)
fo(y,-n,n)
if (abs(x)+abs(y)<=i){
if (!x&&!y) continue;
fo(j,max(abs(x)+abs(y),1),i)
(F(i,x,y)+=(ll)(W(j,x,y)-S(j,x,y))*g[i-j]%mo)%=mo;
fo(j,1,i)
(F(i,x,y)-=(ll)(W(j,0,0)-S(j,x,y))*F(i-j,x,y)%mo)%=mo;
}
fo(i,0,n)
fo(x,-n,n)
fo(y,-n,n)
if (abs(x)+abs(y)<=i) (d+=(ll)W(i,x,y)*g[n-i]%mo)%=mo;
fo(i,0,n){
t=0;
fo(x,-n,n)
fo(y,-n,n)
if ((x||y)&&abs(x)+abs(y)<=n-i) (t+=F(n-i,x,y))%=mo;
fo(x,-n,n)
fo(y,-n,n)
if (abs(x)+abs(y)<=i) (d2+=(ll)t*W(i,x,y)%mo)%=mo;
}
d2=((ll)d2*2%mo+d)%mo;
t=1;
fo(i,1,n) t=(ll)t*all%mo;
ans=((ll)d2*t%mo-(ll)d*d%mo)%mo;
(ans+=mo)%=mo;
printf("%d\n",ans);
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120