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. WPF 截图控件之文字(七)「仿微信」

    前言 接着上周写的截图控件继续更新添加 文字. 1.WPF实现截屏「仿微信」 2.WPF 实现截屏控件之移动(二)「仿微信」 3.WPF 截图控件之伸缩(三) 「仿微信」 4.WPF 截图控件之绘制方 ...

  2. 用JavaScript写一个能开始和暂停的时钟

    //sScriptvar showTime = document.getElementById('seconds') var id =0 function fn(){ var i = 0 var s ...

  3. Unity3D学习笔记11——后处理

    目录 1. 概述 2. 详论 2.1. 实现 2.2. 解析 1. 概述 一般来说,图形渲染引擎都会把帧缓冲(Framebuffer)技术封装成两个接口,其中之一就是后处理(Post-process) ...

  4. LuoguP5022 旅行 (割点,基环树)

    // luogu-judger-enable-o2 #include <cstdio> //#include <iostream> #include <cstring&g ...

  5. selenium基本用法

    一.元素操作 send_keys:赋值 clear:清空 click:点击 from selenium import webdriver from selenium.webdriver.common. ...

  6. java中为什么只存在值传递(以传入自定义引用类型为例)

    java中只有值传递 为什么这么说?两个例子: public class Student { int sage = 20; String sname = "云胡不归"; publi ...

  7. Java SE 9 多版本兼容 JAR 包示例

    Java SE 9 多版本兼容 JAR 包示例 作者:Grey 原文地址:Java SE 9 多版本兼容 JAR 包示例 说明 Java 9 版本中增强了Jar 包多版本字节码文件格式支持,也就是说在 ...

  8. POJ3761 Bubble Sort (组合数学,构造)

    题面 Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be ...

  9. Windows批量修改文件

    如图我是建立了壁纸文件夹 Windows自带的排序方式 如何不用自带的呢? 在这个文件夹里面建一个.txt文件 如下 ok第二步骤 将UTF-8格式改为ANSI格式 点击文件-另存为ANSI格式-替换 ...

  10. QQ高级功能

    本篇文章为微信公众号:酿俗 教学内容请跟着小编一起探索吧! 第一步解锁微信豆影藏内容 随后下载需要的材料,注意!手机可能会提示有病毒!这里使用这些功能报病毒很正常 其实并没有病毒只是手机厂商的安全系统 ...