Language: C++

#include<bits/stdc++.h>
typedef int LL;
const LL maxn=4e2+9,mod=998244353;
LL mul(LL x,LL y){ return 1ll*x*y%mod; }
LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; }
LL dec(LL x,LL y){ return x-=y,x<0?x+mod:x; }
LL n,nod;
LL h[maxn],f[5000][maxn][maxn],fac[maxn],fav[maxn],size[maxn],pow2[maxn];
LL g[maxn][maxn],Tmp[maxn][maxn],a[5000][maxn];
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
LL C(LL N,LL M){
	if(!M) return 1;
	if(N<M) return 0;
	return mul(fac[N],mul(fav[M],fav[N-M]));
}
LL Solve(LL l,LL r,LL dep){
	//printf("%d,%d\n",l,r);
	LL nw(++nod),pre(0),tot(0),num(0);
	size[nw]=r-l+1;
	//if(dep==3) return nw;
	//static LL a[maxn];
	for(LL i=l;i<=r;++i){
		if(h[i]==dep){
			if(pre) a[nw][++tot]=Solve(pre,i-1,dep+1);
			pre=0;
			++num;
		}else{
			if(!pre) pre=i;
		}
	}
	if(pre) a[nw][++tot]=Solve(pre,r,dep+1);
	LL sum(0);
	memset(g,0,sizeof(g));
	g[0][0]=1;
	for(LL i=1;i<=tot;++i){
		LL id(a[nw][i]);
		for(LL x=0;x<=sum;++x){
			for(LL y=0;y<=sum;++y){
				Tmp[x][y]=g[x][y]; g[x][y]=0;
			}
		}
		LL up(size[id]);
		for(LL x=0;x<=sum;++x){
			for(LL y=0;y<=sum;++y) if(Tmp[x][y]){
				for(LL xx=0;xx<=up;++xx){
					for(LL yy=0;yy<=up;++yy){
						g[x+xx][y+yy]=add(g[x+xx][y+yy],mul(Tmp[x][y],f[id][xx][yy]));
					}
				}
			}
		}
		sum+=up;
	}
	//printf("(%d,%d):\n",l,r);
	//for(LL i=0;i<=sum;++i)  printf("%d ",g[i]); puts("");
	/*printf("##1 %d,%d,%d,%d\n",nw,l,r,dep);
	//for(LL i=1;i<=tot;++i) printf("%d ",a[i]); puts("");
	for(LL i=0;i<=sum;++i){
		for(LL j=0;j<=sum;++j) printf("%d ",g[i][j]); puts("");
	}*/
	for(LL i=0;i<=sum;++i){
	    for(LL j=0;j<=sum;++j){
			if(!g[i][j]) continue;
			f[nw][i+num+j][0]=add(f[nw][i+num+j][0],g[i][j]);//不选
			f[nw][i][j+num]=add(f[nw][i][j+num],mul(g[i][j],dec(pow2[sum-i-j],1)));//只选余项
			for(LL x=0;x<=i;++x){
				for(LL y=0;y<=j;++y){
					for(LL z=0;z<=num;++z){
						if(x+y+z){
							f[nw][i-x][j-y+num-z]=add(f[nw][i-x][j-y+num-z],1ll*g[i][j]*C(i,x)%mod*C(j,y)%mod*C(num,z)%mod*pow2[sum-i-j]%mod);
						}
					}
				}
			}
		}
	}
	/*printf("##2 (%d):%d,%d,%d\n",nw,l,r,dep);
	for(LL i=0;i<=size[nw];++i){
		for(LL j=0;j<=size[nw];++j) printf("%d ",f[nw][i][j]); puts("");
	}*/
	return nw;
}
int main(){
	scanf("%d",&n);
	pow2[0]=1; for(LL i=1;i<=n;++i) pow2[i]=mul(pow2[i-1],2);
	fac[0]=1; for(LL i=1;i<=n;++i) fac[i]=mul(fac[i-1],i);
	fav[n]=Pow(fac[n],mod-2); for(LL i=n;i>=1;--i) fav[i-1]=mul(fav[i],i);
	for(LL i=1;i<=n;++i){
		scanf("%d",h+i);
	}
	Solve(1,n,1);
	LL ans(0);
	for(LL i=0;i<=n;++i){
		ans=add(ans,f[1][0][i]);
	}
	printf("%d\n",ans);
	return 0;
}

Compiler output:
/tmp/ccmMNaj1.o: in function `C(int, int)':
a.cc:(.text+0x129): relocation truncated to fit: R_X86_64_PC32 against symbol `fav' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x140): relocation truncated to fit: R_X86_64_PC32 against symbol `fav' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x162): relocation truncated to fit: R_X86_64_PC32 against symbol `fac' defined in .bss section in /tmp/ccmMNaj1.o
/tmp/ccmMNaj1.o: in function `Solve(int, int, int)':
a.cc:(.text+0x1cf): relocation truncated to fit: R_X86_64_PC32 against symbol `size' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x240): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x2b0): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x2cb): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x2d9): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x30d): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x34c): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/ccmMNaj1.o
a.cc:(.text+0x374): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status