题面传送门
首先是二项式反演公式:\(f_n=\sum\limits_{i=n}^{m}{C_{n}^{i}g_i}\)可以得到\(g_n=\sum\limits_{i=n}^{m}{(-1)^{i-n}C_{n}^{i}f_i}\)
这个直接把\(g\)代到\(f\)里面就化一下就出来了。
然后这道题直接求很难求,考虑求出至少\(k\)的答案记为\(dp_k\)
这个可以排好序以后\(O(n^2)\)dp求出来。
然后直接套二项式反演公式就好了,时间复杂度\(O(n^2)\)
code:
#include<bits/stdc++.h>
#define I inline
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define re register
#define RI re int
#define ll long long
#define db double
#define lb long db
#define N 2000
#define K 50
#define mod 1000000009
#define eps (1e-4)
#define U unsigned int
#define it iterator
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define d(x,y) (n*(x-1)+(y))
using namespace std;
int n,m,k,A[N+5],B[N+5],L[N+5];ll frc[N+5],Inv[N+5],dp[N+5][N+5],Ans;I ll C(int x,int y){return frc[x]*Inv[y]%mod*Inv[x-y]%mod;}
I ll mpow(ll x,int y=mod-2){ll Ans=1;while(y) y&1&&(Ans=Ans*x%mod),y>>=1,x=x*x%mod;return Ans;}
int main(){
freopen("1.in","r",stdin);
re int i,j;scanf("%d%d",&n,&k);if((n+k)&1){puts("0");return 0;}k=n+k>>1;for(i=1;i<=n;i++) scanf("%d",&A[i]);for(i=1;i<=n;i++) scanf("%d",&B[i]);for(frc[0]=Inv[0]=i=1;i<=n;i++)frc[i]=frc[i-1]*i%mod,Inv[i]=Inv[i-1]*mpow(i)%mod;
sort(A+1,A+n+1);sort(B+1,B+n+1);dp[0][0]=1;for(i=1;i<=n;i++){
L[i]=L[i-1];while(L[i]<n&&B[L[i]+1]<A[i]) L[i]++;for(dp[i][0]=1,j=1;j<=L[i];j++) dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*(L[i]-j+1))%mod;
}for(i=k;i<=n;i++) Ans+=(i-k)&1?mod-C(i,k)*dp[n][i]%mod*frc[n-i]%mod:C(i,k)*dp[n][i]%mod*frc[n-i]%mod;printf("%lld\n",Ans%mod);
}