容斥原理

看见恰好k个就要容斥

g[i]表示有几个b比a小

dp[i][j]表示前i个数至少有j个大的方案数,dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*(g[i]-j+1),就是可以不匹配,或者在剩下的g[i]-j+1选一个

然后就是容斥了,那个系数搞的不是很清楚,和spring一样

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = , P = 1e9 + ;
int n, k;
ll ans;
ll a[N], b[N], inv[N], facinv[N], fac[N], dp[N][N], g[N];
ll C(int n, int m)
{
return fac[n] * facinv[m] % P * facinv[n - m] % P;
}
int main()
{
scanf("%d%d", &n, &k);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
for(int i = ; i <= n; ++i) scanf("%d", &b[i]);
if((n + k) & )
{
puts("");
return ;
}
k += (n - k) >> ;
sort(a + , a + n + );
sort(b + , b + n + );
inv[] = ; fac[] = facinv[] = ;
for(int i = ; i <= n; ++i)
{
if(i != ) inv[i] = (P - P / i) * inv[P % i] % P;
facinv[i] = facinv[i - ] * inv[i] % P;
fac[i] = fac[i - ] * i % P;
}
for(int i = , j = ; i <= n; ++i)
{
while(a[i] > b[j + ] && j + <= n) ++j;
g[i] = j;
}
for(int i = ; i <= n; ++i) dp[i][] = ;
for(int i = ; i <= n; ++i)
for(int j = ; j <= g[i]; ++j)
dp[i][j] = (dp[i - ][j] + dp[i - ][j - ] * (g[i] - j + ) % P) % P;
for(int i = k; i <= n; ++i) ans = ((ans + (((i - k) & ) ? - : ) * dp[n][i] * fac[n - i] % P * C(i, k) % P) % P + P) % P;
printf("%lld\n", ans);
return ;
}

最新文章

  1. https://zeroc.com/index.html
  2. 《C#图解教程》读书笔记之一:C#和.NET框架
  3. Eclipse设置注释模板
  4. Android 设置EditText光标Curso颜色及粗细
  5. DNS map file in windows
  6. acdream 1408 &quot;Money, Money, Money&quot; (水)
  7. oracle几个函数整理 DECODE() NVL NVL2 NULLIF Coalesce(转)
  8. TensorFlow文本与序列的深度模型
  9. Knockoutjs : Unable to process binding &quot;value:
  10. AVAudioPlayer与MPMusicPlayerController的区别
  11. Python系列-python内置函数
  12. GMA Round 1 新年祝福
  13. MYSQL : The user specified as a definer (&#39;root&#39;@&#39;%&#39;) does not exist
  14. HTTP协议简单认识
  15. Swift5 语言指南(八) 控制流
  16. sql查询:存在A表而不在B表中的数据
  17. Git简明教程二、开始进行版本管理
  18. C++ 编译器用于把源代码编译成最终的可执行程序
  19. .NET IL指令速查表
  20. POJ 2774 求两个串的最长公共前缀 | 后缀数组

热门文章

  1. mysql: Data source rejected establishment of connection, message from server: &quot;Too many connections&quot;
  2. 【Sprint3冲刺之前】项目完成时间表
  3. CentOs中mysql的安装与配置(转)
  4. JS 常用字符串操作
  5. angularJS 自定义指令 分页
  6. 怎么将linux的动态IP设置成静态IP
  7. OpenKM安装(CentOS6)
  8. ios 常见错误整理 持续更新
  9. 开源无广告输入法Rime
  10. LESS和sa