The meaning of problems
Set \ (a_i \) represents the \ (I \) candy energy, \ (B_i \) represents the \ (I \) energy of pills
First may satisfy Conditions, \ (A> B \) to the number of \ (\ + K FRAC {n-2}} {\) .
Because just as (i \) \ the number of poor program requirements, we first find the least \ (i \) number of the program, followed by the binomial inversion find the answer.
First \ (a, b \) in ascending order.
Set \ (h_ {i, j} \) representing the forward \ (I \) candy, at least chose \ (J \) of \ (a> b \) of the number of programs, \ (cnt_i \) represents the ratio of \ (i \) a small number of pills a candy.
有:
\(h_{i,j}=h_{i-1,j}+(cnt_i-(j-1))*h_{i-1,j-1}\)
Set \ (F_i \) represents exactly (I \) \ to \ (a> b \) of the number of programs, \ (G_i \) represents at least \ (I \) of \ (a> b \) of the number of programs.
Apparently \ (n-G_i = F_ {,} * I (Ni)! \) , Then the binomial inversion can.
code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
const int mod=1e9+9;
int n,m,ans;
int a[maxn],b[maxn],cnt[maxn],g[maxn],fac[maxn],inv[maxn];
int f[maxn][maxn];
inline int power(int x,int k)
{
int res=1;
while(k)
{
if(k&1)res=1ll*res*x%mod;
x=1ll*x*x%mod;k>>=1;
}
return res;
}
inline int C(int n,int m)
{
if(n<m)return 0;
return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
scanf("%d%d",&n,&m);
if((n+m)&1){puts("0");return 0;}
m=(n+m)>>1;
fac[0]=1;
for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
inv[n]=power(fac[n],mod-2);
for(int i=n;i;i--)inv[i-1]=1ll*inv[i]*i%mod;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)scanf("%d",&b[i]);
sort(a+1,a+n+1);sort(b+1,b+n+1);
for(int i=1,j=0;i<=n;i++)
{
while(b[j+1]<a[i]&&j<n)j++;
cnt[i]=j;
}
for(int i=0;i<=n;i++)f[i][0]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
f[i][j]=(f[i-1][j]+1ll*max(0,cnt[i]-(j-1))*f[i-1][j-1]%mod)%mod;
for(int i=0;i<=n;i++)g[i]=1ll*f[n][i]*fac[n-i]%mod;
for(int i=m;i<=n;i++)
if((i-m)&1)ans=(ans-1ll*C(i,m)*g[i]%mod+mod)%mod;
else ans=(ans+1ll*C(i,m)*g[i]%mod)%mod;
printf("%d",ans);
return 0;
}