/********************************************************************************
剪个枝就过了~比赛的时候没什么人做,主要是因为位运算的威慑力太大了~
********************************************************************************/
#include <iostream>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <bitset>
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) ( (x) & ( (x) ^ (x - 1) ) )
//typedef long long LL;
//typedef unsigned long long ULL;
typedef __int64 LL;
typedef unsigned __int64 ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<LL>::iterator LI;
typedef set<int>::iterator SI;
const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffff;
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);
const int MAXN = 44;
int test, n, m;
LL ans, arr[MAXN];
bool check(int id, LL buf)
{
for (int i = id + 1; i < n; ++i)
{
buf &= arr[i];
}
return buf < ans;
}
void dfs(int crt, int step, LL buf)
{
ans = min(ans, buf);
if (step >= m)
{
return ;
}
for (int nxt = crt + 1; nxt < n; ++nxt)
{
LL tmp = buf & arr[nxt];
if (!check(nxt, tmp))
{
continue ;
}
dfs(nxt, step + 1, tmp);
}
return ;
}
void ace()
{
int cas = 1;
for (scanf("%d", &test); test--; ++cas)
{
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i)
{
scanf("%I64d", arr + i);
}
sort(arr, arr + n);
ans = INF_LL;
for (int i = 0; i < n; ++i)
{
dfs(i, 1, arr[i]);
}
printf("Case #%d: %I64d\n", cas, ans);
}
return ;
}
int main()
{
ace();
return 0;
}相关推荐
从入门到精通:HyperMesh实体选择全攻略(含2025新界面操作)
本文系统解析了HyperMesh从基础到高级的实体选择技巧,重点介绍了2025新界面的交互逻辑与效率提升。内容涵盖选择模式、框选方法、右键菜单高级选择、图形窗口选择器与命令面板的智能联动,以及利用浏览器和过滤器进行精准定位的实战指南,帮助用户显著提升前处理建模效率。
Hdu 4016 Magic Bitwise And Operation (暴搜 dfs)
题目大意: 在n个数中选取k个数,是他们的按位与最小。 思路分析: 开始往dp想,但是这道题是不满足子问题的。 当前的值最小,但是丢掉了和后面的1错开的最多的状态。 暴搜的剪枝: 1.与后面所有的树相与都比ans小,剪掉,因为越与越小。 2.先将所有的数排序,先取小的。 3.ans可以不断更新,不需要达到k的时候更新,原因和1相同。 #include #incl
DDR5内存命令真值表详解:如何正确解析JESD79-5标准中的关键指令
本文深度解析JESD79-5标准中的DDR5内存命令真值表,将其视为动态通信协议进行拆解。详细阐述了1-Cycle与2-Cycle命令的区别、Bank Group寻址机制以及模式寄存器(MR)操作流程,为硬件与固件工程师提供了从信号解析到系统调试的完整实战指南,是理解和优化高性能计算平台内存子系统的核心。
hdu 4016搜索
这题看完本来以为是找规律的,可找了半天也没找出啥规律,翻了一下解题报告,说是搜索加剪枝,学了一下,就过了。 /* * hdu4016/win.cpp * Created on: 2012-11-9 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstr...
《大数据之路:阿里巴巴大数据实践》-第1篇 数据技术篇 -第3章数据同步
我们将数据釆集分为日志采集和数据库数据同步两 部分。数据同步技术更通用的含义是不同系统间的数据流转,有多种不 同的应用场景。主数据库与备份数据库之间的数据备份,以及主系统与 子系统之间的数据更新,属于同类型不同集群数据库之间的数据同步。 另外,还有不同地域、不同数据库类型之间的数据传输交换,比如分布 式业务系统与数据仓库系统之间的数据同步。对于大数据系统来说,包 含数据从业务系统同步进入数据仓库和数据从数据仓库同步进入数据 服务或数据应用两个方面。本章侧重讲解数据从业务系统同步进入数据 仓库这个环节,但其适
[xboard-real6410]39 real6410中的BL1和BL2实验及流程分析
文章目录uboot控制uboot 流程uboot加载kernel uboot控制 uboot 流程 uboot加载kernel
hdu 4016 Magic Bitwise And Operation 搜索
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4016 题目意思:从n个数中挑选m个数,使得这m个数按位与之后结果最小,输出最小值。 For example, there are three integers 5, 6 and
Linux内核4.14版本——drm框架分析(1)——drm简介
本文介绍了DRM架构的发展历史、驱动框架以及简单示例,旨在帮助读者了解DRM架构的形成、功能流程实现。
[搜索] hdu 4016 Magic Bitwise And Operation
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4016 Magic Bitwise And Operation Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 1315
虚拟机安装VMware Tools
单击虚拟机-->安装VMware Tool 安装之后会有一个VMware Tools硬盘,里面有VMware Tools.tar.gz的压缩包 按照提示解压它,然后执行vmware-install.pl安装VMware Tools 将安装包放到/tmp目录下。可以直接拽过去,也可以使用cp或者mv命令 进入tmp文件目录并解压此文件包 cd /tmp ...
[PCIe5.0] 2.2.7.1 TPH Rules
TPH 机制通过硬件提示优化数据流,适用于高性能计算和存储场景。
The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup hdu 4016 Magic Bitwise And Operation
原题传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4016 这个题很明显是搜索,但是这个题对剪枝的要求很高!很高!由于n的最大值是40,也就是暴利的搜索是没法做的,因为我知道,暴利的搜索也就可以搜到十几。 当我知道,这场比赛和接下来的比赛都是一个人出的题的时候,我觉得我还是把每一个题弄明白为好。 这个题的剪枝不是我的思路,思路源自网络,呵呵,最终
2. Android_逆向的历史与发展
学完本节,希望你能够:了解 Android 逆向工程的发展历程,从早期 APK 破解到现代应用保护;入门先把这几类「在干啥」搞清楚,后面学脱壳、反反调试会顺很多。(反编译 APK 得到的类汇编代码,相当于程序的「菜谱」)就能绕过验证,到后来混淆、加固、反调试一起上,逆向难度越来越高。(第三节 什么是 CPU 指令集),帮你搞清楚「反汇编看到的那些指令」是从哪来的、和 Android 逆向有啥关系。有必要——先搞清「没加固时怎么玩」,再学脱壳和对抗,思路才顺。读起来费劲,但逻辑还在,耐心一点还能跟。
【HDU4016】Magic Bitwise And Operation
题目意思是从n个数中选k个数,进行与运算,找到最小值。使用DFS。
Outlook Express 6 (OE6) for Win7/Win8/Win10
英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。
Camera2Demo
在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作
hdu 4016 Magic Bitwise And Operation
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4016 题意:从给出的N个数中,选出K个数进行与运算,求出最小值 一看到这题目,哎,就知道暴力是绝对超时的,可是之后,就没之后…………………… 看了网上的思路,这剪枝太有技巧了,orz 思路如下: 1.从当前值开始,如果选上剩下的所有,也不能小于已得最优值的话,返回。2.最优值不用等到累积选到...
IEM模型,地表粗糙度模拟
利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟
HDU 4016 Magic Bitwise And Operation 暴搜+剪枝
这个题得用一下位运算‘&’的性质:若c=a&b,则c 设置long long最大值时可以这么写 const long long MAX=(~(0ULL)>>1); #include #include #include using namespace std; const int N=45; const long long MAX=(~(0ULL)>>1); int t,c,
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
HDU 4016 Magic Bitwise And Operation
题目链接~~>
HDU 4016 Magic Bitwise And Operation
题目大意:从N个数中选k个数使得&运算后结果最小 解题思路:经典的搜索+剪枝,抓住每次&运算之后得到的值肯定 #include #include #include #include using namespace std; const long long inf = (1LL<<62) - 1; int n, k; long long num[45], sum[45], ans;
HDU 4016 Magic Bitwise And Operation (暴搜)
题意: 给出n个数,要求你在其中选k个数使 & 操作的结果最小 分析: 一开始看到这题,一位是状压dp乱搞什么的,一看就知道不是我的题,扔锅。。。 好吧,一开始是贪心的想法,以最小的数为底贪心取出其他数,结果发现连样例都过不了,果断发现了一组会挂的数据 0000111 1000011 01111100 这样就挂了、、 比赛完后搜了一下,发现居然是暴搜!! 主要的
Hdu 4016 Magic Bitwise And Operation
题意:给n个最多2^60的数,求其中m个的最小与(&)和 思路: 关键在于与运算的规律:一个数不断参与与运算一定是越变越小 另外要注意的并不一定前m小的数的与和最小, 例子:(二进制)1011,0011,1100 所以这题是dfs加剪枝 剪枝:1. 一边dfs一边更新ans,因为ans不可能变大 2. 当当前值与剩余数的与和作与运算的结果大于ans,
hdu 4016 Magic Bitwise And Operation(dfs)
Problem Description Given n integers, your task is to pick k out of them so that the picked number are minimum when do bitwise “AND” among all of them. For example, there are three integers 5, 6 a
【HDU4016】Magic Bitwise And Operation(dfs)
题目链接 Magic Bitwise And Operation Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 1716 Accepted Submission(s): 709 Problem...
HDU 4016 Magic Bitwise And Operation(dfs+剪枝)
Given n integers, your task is to pick k out of them so that the picked number are minimum when do bitwise “AND” among all of them. For example, there are three integers 5, 6 and 7. You are asked to pick two of them. Your possible strategy is (5, 6), (5, 7
1087



被折叠的 条评论
为什么被折叠?



