题目链接

题解

知识点:线性dp,位运算。

考虑设 \(f_{i,j}\) 表示考虑了前 \(i\) 个数字,与和为 \(j\) 的方案数。转移方程显然。

注意初值为 \(f_{0,63} = 1\) 表示空集,此时注意 \(k = 6\) 时要减去空集这一个方案。

当然也可以选择不加入空集,但dp过程需要特别处理只选自己的方案。

时间复杂度 \(O(64n)\)

空间复杂度 \(O(64n)\)

代码

#include <bits/stdc++.h>
using namespace std;
using ll = long long; const int P = 1e9 + 7; int a[200007];
int f[200007][64];
bool solve() {
int n, k;
cin >> n >> k;
for (int i = 1;i <= n;i++) cin >> a[i];
f[0][63] = 1;
for (int i = 1;i <= n;i++) {
for (int j = 0;j <= 63;j++) f[i][j] = 0;
for (int j = 0;j <= 63;j++) {
(f[i][j] += f[i - 1][j]) %= P;
(f[i][a[i] & j] += f[i - 1][j]) %= P;
}
}
int ans = 0;
for (int i = 0;i <= 63;i++) if (__builtin_popcount(i) == k) (ans += f[n][i]) %= P;
cout << ans - (k == 6) << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

CF1829H Don't Blame Me的更多相关文章

  1. git技巧记录--blame

    git blame [-L<m,n>] FilePath 可以查看代码每一行是谁写的(根据该行最后一次改动情况), -L表示要查看的行数范围, m: 起始行数, n:结束行数. 方便快速定 ...

  2. 转:[版本控管]TortoiseSVN 使用,抓出兇手,使用 Blame 查看每一行最後修改的人是誰

    类似的官方的使用手段有: https://tortoisesvn.net/docs/nightly/TortoiseSVN_zh_CN/tsvn-dug-blame.html from: http:/ ...

  3. 查找问题的利器 - Git Blame

    原文: http://gitbook.liuhui998.com/5_5.html  如果你要查看文件的每个部分是谁修改的, 那么 git blame 就是不二选择. 只要运行'git blame [ ...

  4. 从《BLAME!》说开去——新一代生产级卡通真实感混合的渲染方案

    <BLAME!>是Polygon Pictures Inc.(以下简称PPI)创业33周年以来制作的第一部CG剧场电影,故事来自于贰瓶勉的同名漫画作品(中文译名为<探索者>或者 ...

  5. Git基础 - git blame

    当想知道一段代码历史上有哪些人修改时,可以使用git blame查看,正如其名,当你看到那段让你抓狂的代码时,一定想找出是谁写的来一顿blame吧 : ) 使用方法 icebug@localhost: ...

  6. [Practical Git] Show who changed a line last with git blame

    When working on a file, we often want to know who made certain changes last; we can use git blame to ...

  7. "BLAME" is out.

    The latest feature animation film "BLAME" is watchable on the Netflix. Rendering was done ...

  8. 如果你要查看文件的每个部分是谁修改的, 那么 git blame 就是不二选择

    原文: http://gitbook.liuhui998.com/5_5.html 如果你要查看文件的每个部分是谁修改的, 那么 git blame 就是不二选择. 只要运行'git blame [f ...

  9. 不常用但很有用的git show 和 git blame

    团队使用git 合作时,可能遇见想要查看一段比较难以阅读代码, 此时可能需要联系最新的修改者是哪位,这时候最有用的最快捷的方法就是git blame 啦, 这个指令的output是一个文件的各个区域段 ...

  10. git blame 查看某行代码提交记录

    1. 在当前git项目目录下执行 git blame -L 38,38 <filename> 例子:  git blame -L 38,38 src/component/BarCode/i ...

随机推荐

  1. socket TCP DPT 网络编程

    复习: ARP协议: 广播和单播 通过ip地址获得mac地址 机器A发起一个arp请求(只包含A的ip地址) 交换机接收到请求,广播这条消息 所有的机器都会接受到这条请求,只有需要寻找的机器B的ip地 ...

  2. P5728 【深基5.例5】旗鼓相当的对手

    1.题目介绍 2.题解 2.1 二维数组 思路 主要熟悉vector创建二维数组的方法 vector<vector> ans(N,vector(3)); 这里第一个元素表明数组大小,第二个 ...

  3. 【C/C++】sscanf函数和正则表达式

    此文所有的实验都是基于下面的程序:char str[10];for (int i = 0; i < 10; i++) str[i] = '!';执行完后str的值为str = "!!! ...

  4. 今天是个好日子,TaxCore(POS软件)备案指北

    POS软件是什么?你好意思吗,还在用老掉牙的Winform. 关于POS 销售终端--POS(point of sale)是一种多功能终端,把它安装在信用卡的特约商户和受理网点中与计算机联成网络,就能 ...

  5. Cloudquery的学习安装与使用

    Cloudquery的学习安装与使用 下载 官方下载地址: https://www.cloudquery.club/download https://pan.baidu.com/s/1a7XOrnMU ...

  6. [转帖]tidb Modify Configuration Dynamically

    https://docs.pingcap.com/tidb/v6.5/dynamic-config This document describes how to dynamically modify ...

  7. [转帖]新版 Elasticsearch 中的强悍插件 X-pack

    https://zhuanlan.zhihu.com/p/36337697   3 人赞同了该文章 作者:Alan 岂安科技运维工程师努力踏上一条为后人留坑的运维之路.(逃 1 前言 Elk 日志可视 ...

  8. [转帖]goofys

     Goofys is a high-performance, POSIX-ish Amazon S3 file system written in Go     Overview Goofys all ...

  9. 【转帖】Linux开发工具 — readelf、objdump、hexdump

    本博文的主要内容是:1)readelf工具查看ELF文件的信息:2)hexdump工具查看这块内存:3)objdump工具对文件进行反汇编. 前一段时间对Linux不熟,所以很多命令不知道.学习C时候 ...

  10. [转帖]kubernetes service 和 kube-proxy详解

    https://plantegg.github.io/2020/01/22/kubernetes%20service/ 性能情况.. service 模式 根据创建Service的type类型不同,可 ...