ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ARC144 D - AND OR Equation

2022-08-08 09:32:20  阅读:32  来源: 互联网

标签:ch int res Equation ARC144 le sum LL


ARC144 D - AND OR Equation

Solution

首先可以猜测和答案仅和每一个二进制位以及\(f(0)\)有关系,不妨把按位\(\operatorname{AND}\)和按位\(\operatorname{OR}\)对应到集合的运算上去,那么

\[f(A + B) = f(A \cup B) + f(A \cap B) \]

然后把每个集合拆一下,可以得到\(f(A) = \sum_{i \in A} f(\left\{i\right\}) - (|A| - 1)f(\varnothing)\)

设\(g(A) = f(A) - f(\varnothing)\),则\(g(A) = \sum_{i \in A} g({i})\)

\(f\)就由\(f(0)\)和每一个二进制位唯一确定了。

设\(f(0)=c,f(2^i) - c=x_i\),这样就把原问题转化成了计数有多少组\(\left\{c,x \right\}\),满足

\[-c \le s^-,s^+ \le k - c \]

其中\(s^-=\sum [x_i < 0] x_i, s^+ = \sum [x_i > 0] x_i\)

把\(c\)解出来,得到\(-s^- \le c \le k - s^+\)

那么对于一组\(x\),合法的\(c\)有\(k - s^+ + s^- + 1 = k - \sum |x_i| + 1\)个

答案就是

\[\sum (k + 1 - \sum|x_i|) \]

然后枚举有多少个\(x_i\)不为\(0\),这东西用隔板法就可以做了

\[\sum_{i=0}^n 2^i \binom{n}{i} \binom{k + 1}{i + 1} \]

Code

点我看代码(。・ω・。)
#include <cstdio>
#include <iostream>
#define LL long long
using namespace std;
template <typename T>
inline void read(T &x) {
	x = 0; int f = 0; char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
	for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
	if(f) x = ~x + 1;
}
const LL P = 998244353;
LL fpow(LL x, LL pnt = P - 2) {
	pnt %= (P - 1);
	LL res = 1;
	for(; pnt; pnt >>= 1, x = x * x % P) if(pnt & 1) res = res * x % P;
	return res;
}
const LL N = 1e6 + 10;
LL n, k, ans;
LL fac[N], ifac[N], pw[N];
LL C(int x, int y) {return y < 0 ? 0 : fac[x] * ifac[y] % P * ifac[x - y] % P;}
int main() {
	read(n), read(k);
	fac[0] = 1; for(int i = 1; i <= n + 1; ++i) fac[i] = fac[i - 1] * i % P;
	ifac[n + 1] = fpow(fac[n + 1]); for(int i = n + 1; i; --i) ifac[i - 1] = ifac[i] * i % P;
	pw[0] = 1; for(int i = 1; i <= n + 1; ++i) pw[i] = (k - i + 2) % P * pw[i - 1] % P;
	for(int i = 0, p2 = 1; i <= n; ++i, p2 = p2 * 2 % P) ans = (ans + C(n, i) * p2 % P * pw[i + 1] % P * ifac[i + 1]) % P;
	printf("%d\n",ans); 
}

标签:ch,int,res,Equation,ARC144,le,sum,LL
来源: https://www.cnblogs.com/DCH233/p/16560654.html

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有