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);
}

ARC144 D - AND OR Equation的更多相关文章

  1. CodeForces460B. Little Dima and Equation

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  3. HDU 5937 Equation

    题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...

  4. coursera机器学习笔记-多元线性回归,normal equation

    #对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...

  5. CF460B Little Dima and Equation (水题?

    Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...

  6. Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)

    ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...

  7. ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

    Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  8. [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...

  9. hdu 2199 Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

随机推荐

  1. 浅谈Meet in the middle——MITM

    目测观看人数 \(0+0+0=0\) \(\mathrm{Meet\;in\;the\;middle}\)(简称 \(\rm MITM\)),顾名思义就是在中间相遇. 可以理解为就是起点跑搜索树基本一 ...

  2. Odoo14 groups && rule

    # Odoo14 groups && rule # admin账户以及权限的来源: # admin创建代码在:odoo/odoo/addons/base/data/res_users_ ...

  3. docker容器技术基础入门

    目录 docker容器技术基础入门 容器(Container) 传统虚拟化与容器的区别 Linux容器技术 Linux Namespaces CGroups LXC docker基本概念 docker ...

  4. Apache Hudi vs Delta Lake:透明TPC-DS Lakehouse性能基准

    1. 介绍 最近几周,人们对比较 Hudi.Delta 和 Iceberg 的表现越来越感兴趣. 我们认为社区应该得到更透明和可重复的分析. 我们想就如何执行和呈现这些基准.它们带来什么价值以及我们应 ...

  5. 利用图像二维熵实现视频信号丢失检测(Signal Loss Detection)

    1 图像二维熵 图像二维熵作为一种特征评价尺度能够反映出整个图像所含平均信息量的高低,熵值(H)越大则代表图像所包含的信息越多,反之熵值(H)越小,则图像包含的信息越少.对于图像信息量,可以简单地认为 ...

  6. thinkphp 5 及一下或php项目里实现模糊查询

    想在thinkPHP或者PHP项目实现模糊查询怎么实现呢? 今天在网上搜了一下用 mysql里的 like 就可以实现 怎么用呢? 看代码: 错误用法: where('title','like',$s ...

  7. python包合集-shutil

    一.简介 shutil是 python 中的高级文件操作模块,与os模块形成互补的关系,os主要提供了文件或文件夹的新建.删除.查看等方法,还提供了对文件以及目录的路径操作.shutil模块提供了移动 ...

  8. spring使用junit单元测试

    <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test& ...

  9. 定时器控制单只LED灯

    点击查看代码 #include <reg51.h> #define uchar unsigned char #define uint unsigned int sbit LED=P0^0; ...

  10. C++ Protobuf

    Protobuf protobuf (protocol buffer) 是谷歌内部的混合语言数据标准.通过将结构化的数据进行序列化(串行化),用于通讯协议.数据存储等领域的语言无关.平台无关.可扩展的 ...