`
holoblog
  • 浏览: 1224263 次
博客专栏
E0fcf0b7-6756-3051-9a54-90b4324c9940
SQL Server 20...
浏览量:18888
文章分类
社区版块
存档分类
最新评论

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 7. You are asked to pick two of them. Your possible strategy is (5, 6), (5, 7) or (6, 7). The values when do bitwise and all the picked numbers together are as follows:
5 and 6 = 4
5 and 7 = 5
6 and 7 = 6
The smallest one is 4.
剪枝:
1.从当前值开始,如果选上剩下的所有,也不能小于已得最优值的话,返回。这里可以先进行一下预处理,即逆序与一下, 暂存结果。这样可以减到178ms。
2.最优值不用等到累积选到k数才更新,而是不断更新,因为与运算结果比原来两个都小,所以这也是一个剪枝。
3.预处理,从小到大排序,可想而知,先选小的,得到的最优值更接近于结果,是个强剪枝。

代码如下:




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics