ARC144 D - AND OR Equation
ARC144 D - AND OR Equation
Solution
首先可以猜测和答案仅和每一个二进制位以及\(f(0)\)有关系,不妨把按位\(\operatorname{AND}\)和按位\(\operatorname{OR}\)对应到集合的运算上去,那么
\]
然后把每个集合拆一下,可以得到\(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\}\),满足
\]
其中\(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\)个
答案就是
\]
然后枚举有多少个\(x_i\)不为\(0\),这东西用隔板法就可以做了
\]
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的更多相关文章
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)
,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...
- 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 ...
- [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 ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- Redis系列5:深入分析Cluster 集群模式
Redis系列1:深刻理解高性能Redis的本质 Redis系列2:数据持久化提高可用性 Redis系列3:高可用之主从架构 Redis系列4:高可用之Sentinel(哨兵模式) 1 背景 前面我们 ...
- 使用.NET简单实现一个Redis的高性能克隆版(三)
译者注 该原文是Ayende Rahien大佬业余自己在使用C# 和 .NET构建一个简单.高性能兼容Redis协议的数据库的经历. 首先这个"Redis"是非常简单的实现,但是他 ...
- Apache DolphinScheduler 使用文档(2-3/8):集群规划及环境准备
本文章经授权转载,原文链接: https://blog.csdn.net/MiaoSO/article/details/104770720 目录 2. 集群规划 2.1 集群配置 2.2 软件版本 2 ...
- 总结-LCT
题单: https://www.zybuluo.com/xzyxzy/note/1027479 LuoguP3203 [HNOI2010]弹飞绵羊 动态加边,删边 #include <cstdi ...
- Linux 09 Vim
参考源 https://www.bilibili.com/video/BV187411y7hF?spm_id_from=333.999.0.0 版本 本文章基于 CentOS 7.6 概述 Vi Vi ...
- Excel 运算符(二):比较运算符
比较运算符用于对两个数据进行比较运算,其结果为 TRUE(真)或 FALSE(假). 运算符 含义 实例 结果 = 等于 =2=3 FALSE < 小于 =5<2 FALSE > 大 ...
- Swift中的Result 类型的简单介绍
Swift 5引入了一个新的Result类型, 它使用枚举来处理异步函数的结果. 苹果文档对该类型的描述: A value that represents either a success or a ...
- C语言:多功能计算器程序说明书
好家伙,3000字终于写完了 一.题目:多功能科学计算器 二.内容: (1)概述或引言 开发环境为Visual C++ 目前已实现的功能: (1)解二元一次方程.一元二次方程 (2)进行矩阵相加.相减 ...
- AVL tree 高度上下界推导
1. 最大高度对应 Node 数量 \(N_{h}\) 的递归公式 设有一棵 AVL tree 的高度为 \(h\), 对于该树, 构成该树的最少 node 数量为 \(N_{h}\) . 有: 最坏 ...
- 面试突击84:Spring 有几种事务隔离级别?
Spring 中的事务隔离级别和数据库中的事务隔离级别稍有不同,以 MySQL 为例,MySQL 的 InnoDB 引擎中的事务隔离级别有 4 种,而 Spring 中却包含了 5 种事务隔离级别. ...