Codeforces 1342E 二项式反演

原题题面

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值