第一道容斥

\(ans[i] = \sum_{j = 0}^{min(cnt, n / 2)} (-1)^j \tbinom{cnt}{j} \tbinom{n - 2*j + k - 1}{k - 1}\)

i 为 [2, 2k]

cnt是满足x, y小于等于k 且 x + y = i 的对的种类数

后面那个组合数是除了j对 数剩下的数的取值

即\(\sum_{t = 1}^{k} X_t = n - 2j\)

\(X_t\)指t的出现次数

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 4005;
const double eps = 1e-9;
const long long P = 998244353;
int n, k;
long long jie[N], jv[N], inv[N], tot[N];
long long C(long long x, long long y){
return jie[x] * jv[x - y] % P * jv[y] % P;
} int main() {
scanf("%d%d", &k, &n);
jie[0] = inv[0] = jv[0] = jie[1] = inv[1] = jv[1] = 1;
for(int i = 2; i <= n + k; ++i){
jie[i] = jie[i - 1] * i % P;
inv[i] = (P - P / i) * inv[P % i] % P;
jv[i] = jv[i - 1] * inv[i] % P;
}
for(int i = 1; i <= k; ++i) ++tot[i + 1], --tot[i + k + 1];
for(int i = 1; i <= k + k; ++i) tot[i] += tot[i - 1]; //存在另一个数y满足x + y = i的x有多少个
for(int i = 2; i <= k + k; ++i){
long long cnt = ((tot[i] + 1) >> 1), ans = 0;
for(int j = 0, d = 1; j <= cnt && j + j <= n; ++j, d = P - d){
ans = (ans + 1ll * d * C(cnt, j) % P * C(n - (j << 1) + k - 1, k - 1) % P) % P;
// d = (-1)^j 选择哪几对 剩下的数取哪些
}
printf("%lld\n", ans);
}
return 0;
}

ATR102E Stop. Otherwise... [容斥]的更多相关文章

  1. POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)

      题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...

  2. HDU 4059 容斥初步练习

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  3. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  4. 【BZOJ-4455】小星星 容斥 + 树形DP

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 137[Submit][Status] ...

  5. cf#305 Mike and Foam(容斥)

    C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. UVa12633 Super Rooks on Chessboard(容斥 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...

  7. PE-1 & 暴模|容斥

    题意: 求1000以下3或5的倍数之和. SOL: 暴模也是兹瓷的啊... 那么就想到了初赛悲催的滚粗...容斥忘了加上多减的数了... 然后对着题...T = 3*333*(1+333)/2 + 5 ...

  8. HDU 5838 (状压DP+容斥)

    Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...

  9. hdu 5792(树状数组,容斥) World is Exploding

    hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...

随机推荐

  1. 02-HTML之head标签

    head标签 head内常用标签表 标签 类型 意义 <title></titile> 双闭合标签 定义网页标题 <style></style> 双闭合 ...

  2. NFV论文集(二)

    一 文章名称:VNF Placement with Replication for Load Balancing in NFV Networks 发表时间:2017 期刊来源:ICC: IEEE In ...

  3. Median String CodeForces - 1144E

    You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is le ...

  4. Day2 Numerical simulation of optical wave propagation之标量衍射理论基本原理(二)

    2.麦克斯韦方程组的简单行波解 讨论通过线性.各向同性.均匀.无色散.无限电荷和电流的电介质材料的光波传输.在这种情况下,介质具有如下属性: (1)推导获得波动方程( 由麦克斯韦方程组导出的.描述电磁 ...

  5. 解决sqoop连接mysq错误

    一.问题描述 1.由于当前集群没有配置Zookeeper.hcatalog.accumlo,因此应该在sqoop的配置文件中注释掉判断Zookeeper.hcatalog.accumlo路径是否正确的 ...

  6. linux虚拟机桥接网络配置

    版权声明:经验之谈,不知能否换包辣条,另,转载请注明出处. https://blog.csdn.net/zhezhebie/article/details/75035997 前言:我是最小化安装cen ...

  7. webdriver原理、协议

    1.webdriver client的原理是什么? 当测试脚本启动firefox的时候,selenium-webdriver 会首先在新线程中启动firefox浏览器.如果测试脚本指定了firefox ...

  8. PreparedStatement 与 Statement 的区别

    1. PreparedStatement 接口继承 Statement, PreparedStatement 实例包含已编译的 SQL 语句,所以其执行速度要快于 Statement 对象. 2.作为 ...

  9. 关于spring的源码的理解

    从最基础的Hello World开始. spring的Hello World就三行代码: public void test() { ApplicationContext context = new C ...

  10. opencv自带fast_math.hpp

    cvRound cvFloor cvCeil cvIsNaN cvIsInf