1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
int dp[666][666];
int n,k;
int g[666],sum[666],to[666];
signed main()
{
n=read(),k=read();
g[0]=1;for(int i=2;i<=2*n;i+=2) g[i]=1ll*(i-1)*g[i-2]%mod;
int a,b;
R(i,1,k) a=read(),b=read(),sum[a]=sum[b]=1,to[a]=b,to[b]=a;
R(i,1,2*n) sum[i]+=sum[i-1];
L(i,1,2*n) R(j,i+1,2*n)
{
a=0;
R(k,i,j) if(to[k]&&(to[k]<i||to[k]>j)) a=1;
if(a) continue;
dp[i][j]=g[(j-i+1)-(sum[j]-sum[i-1])];
R(k,i,j-1) dp[i][j]=(dp[i][j]-1ll*dp[i][k]*g[(j-k)-(sum[j]-sum[k])]%mod+mod)%mod;
}
//R(i,1,2*n) {R(j,i+1,2*n) printf("%lld ",dp[i][j]);puts("");}
int ans=0;
R(i,1,2*n) R(j,i+1,2*n) ans=(ans+1ll*dp[i][j]*g[2*n-(j-i+1)-sum[i-1]-(sum[2*n]-sum[j])])%mod;
writeln(ans);
}
|