& -- 位运算之一,有0则0

原题链接  Problem - 1514B - Codeforces

题目

Example
input
2
2 2
100000 20
output
4
226732710

题意

t个测试样例,在每个样例中

数组有n个数,数字范围[ 0, 2- 1]

使得数组每个数&后,结果=0,并且这n个数的和要尽量大

输出有多少个这样的数组

解析

数组每个数&后,结果=0  -->每一位至少一个0

数要尽量大  -->只要这一位可以 != 0, 就为 1

先假设每个数都为2k - 1, (每个数的每一位都=1),

对于每一位有且仅有一个数=0,有n种选法.

代码

#include <iostream>

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

int main()
{
int t; cin >> t;
while(t --)
{
int n, k;
ll res = 1;
cin >> n >> k;
while(k--)
res = res*n%mod;
cout << res << endl;
}
return 0;
}

补充

---- 一个难一点的&运算 Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400 - la-la-wanf - 博客园 (cnblogs.com)

Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维的更多相关文章

  1. Codeforces Round #721 (Div. 2)A. And Then There Were K(位运算,二进制) B1. Palindrome Game (easy version)(博弈论)

    半个月没看cf 手生了很多(手动大哭) Problem - A - Codeforces 题意 给定数字n, 求出最大数字k, 使得  n & (n−1) & (n−2) & ...

  2. Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)

    链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...

  3. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】

    A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #267 (Div. 2) B. Fedor and New Game【位运算/给你m+1个数让你判断所给数的二进制形式与第m+1个数不相同的位数是不是小于等于k,是的话就累计起来】

    After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...

  5. Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)

    Problem   Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...

  6. Codeforces Round #306 (Div. 2), problem: (B) Preparing Olympiad【dfs或01枚举】

    题意: 给出n个数字,要求在这n个数中选出至少两个数字,使得它们的和在l,r之间,并且最大的与最小的差值要不小于x.n<=15 Problem - 550B - Codeforces 二进制 利 ...

  7. Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation

    还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门  Problem - D - Codeforces 题意 n个数字,n ...

  8. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  9. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

随机推荐

  1. How to Rebase Git Branch

    转自:How to Rebase Git Branch (with 3 steps) | Git Rebase | W3Docs Steps to rebasing branch Fetching c ...

  2. springcloud学习00-开发工具相关准备

    用maven构建springcloud项目,目录结构(图片来源:https://blog.csdn.net/qq_36688143/article/details/82755492) 1.maven ...

  3. vue学习过程总结(02)- 网上开源项目vue-element-admin的启动

    1.功能丰富的项目:https://github.com/PanJiaChen/vue-element-admin.git 因为我配置的时候,遇到许多的问题,用了一天半才启动的,所以安着他文档一步一步 ...

  4. DDOS防御----CENTOS 内核TCP参数优化

    0x01 环境 attact作为攻击发起方,安装有hping server作为被攻击方,修改内核TCP参数.使用操作系统CENTOS7 0x02 步骤 一.发起攻击 修改TCP最大SYN连接数 使用a ...

  5. Cobalt Strike之网站克隆

    点击 attack --> Web-dirve-by --> clone file 填写你要克隆的网站.带有端口 Clone URL:克隆目标网站的URL 注意问题:URL需要添加http ...

  6. 生产环境频繁内存溢出,原来就是因为这个“String类”

    摘要:如果在程序中创建了比较大的对象,并且我们基于这个大对象生成了一些其他的信息,此时,一定要释放和这个大对象的引用关系,否则,就会埋下内存溢出的隐患. 本文分享自华为云社区<[高并发]你敢信? ...

  7. react核心?

    虚拟DOM, Diff算法, 遍历key值 react-dom: 提供了针对DOM的方法,比如:把创建的虚拟DOM,渲染到页面上 或 配合ref来操作DOM react-router

  8. ZooKeeper 面试题?

    ZooKeeper 是一个开放源码的分布式协调服务,它是集群的管理者,监视着集群 中各个节点的状态根据节点提交的反馈进行下一步合理操作.最终,将简单易用 的接口和性能高效.功能稳定的系统提供给用户. ...

  9. Nacos如果加载不到配置文件的Debug

    进入  com.alibaba.cloud.nacos.client.NacosPropertySourceLocator#loadApplicationConfiguration  这个方法 com ...

  10. Thread 类中的 yield 方法有什么作用?

    使当前线程从执行状态(运行状态)变为可执行态(就绪状态). 当前线程到了就绪状态,那么接下来哪个线程会从就绪状态变成执行状态呢?可 能是当前线程,也可能是其他线程,看系统的分配了.