Codeforces 1342E 二项式反演

博客详细介绍了如何应用二项式反演解决Codeforces上的一个问题,即在n×n的棋盘上放置n个皇后,使得每个空格都受到攻击且恰好有k对皇后互相攻击。通过分析输入输出格式、样例,作者推导出解题思路,利用二项式反演求解,最终给出AC代码并分享了编程过程中的难点和体会。
摘要由CSDN通过智能技术生成

原题题面

Calculate the number of ways to place n rooks on n×n chessboard so that both following conditions are met:

each empty cell is under attack;
exactly k k k pairs of rooks attack each other.
An empty cell is under attack if there is at least one rook in the same row or at least one rook in the same column. Two rooks attack each other if they share the same row or column, and there are no other rooks between them. For example, there are only two pairs of rooks that attack each other in the following picture:
在这里插入图片描述
One of the ways to place the rooks for n = 3 n=3 n=3 and k = 2 k=2 k=2.

Two ways to place the rooks are considered different if there exists at least one cell which is empty in one of the ways but contains a rook in another way.
The answer might be large, so print it modulo 998244353 998244353 998244353.

输入格式

The only line of the input contains two integers n n n and k k k ( 1 ≤ n ≤ 200000 1\leq n\leq 200000 1n200000; 0 ≤ k ≤ n ( n − 1 ) 2 0\leq k\leq \frac{n(n−1)}{2} 0k2n(n1)).

输出格式

Print one integer — the number of ways to place the rooks, taken modulo 998244353 998244353 998244353.

输入样例

1337 42

输出样例

807905441

题面分析

考虑到至少每个行或每个列都要有棋子,每行或每列都有一个棋子,那假设每一行都有棋子,再把答案乘2即可。
稍加推导可知,如果有 k k k个棋子属于相互攻击的状态,那么它们应该占据了 n − k n-k nk列,证明略。
由此可知,如果所有的棋子都能排成一列,那此时存在 n − 1 n-1 n

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值