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