CF981D.Bookshelves
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Miraculously, Mr Keks was promoted and now he is moving into a new office.
He learned that in the new office he will have not a single bookshelf, but exactly k bookshelves. He decided that the beauty of the k shelves is the bitwise AND of the values of all the shelves.
He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on k shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty.
克克斯先生是比特兰的一名典型白领。
他的办公室里有一个书架,上面摆放着若干本书,每本书都有一个正整数价格。
克克斯先生将书架的“价值”定义为该书架上所有书的价格之和。
神奇的是,克克斯先生得到了晋升,即将搬入一间新办公室。
他得知,在新办公室中,他将不再只有一个书架,而是恰好有 k 个书架。他将这 k 个书架的“美观度”定义为所有书架价值的按位与(bitwise AND)。
他还决定不花时间重新整理书籍,因此他会把最前面的若干本书放在第一个书架上,接下来的若干本书放在第二个书架上,依此类推。当然,每个书架上至少要放一本书。这样,他便能将全部书籍恰好分配到 k 个书架上,使得书架的美观度尽可能大。请计算这个可能的最大美观度。
输入格式
The first line contains two integers n and k (1≤k≤n≤50) — the number of books and the number of shelves in the new office.
The second line contains n integers a1,a2,…an, (0<ai<250) — the prices of the books in the order they stand on the old shelf.
第一行包含两个整数 n 和 k(1≤k≤n≤50)—— 分别表示书的总数和新办公室中书架的数量。
第二行包含 n 个整数 a1,a2,…,an(0<ai<250)—— 表示这些书在旧书架上从左到右的单价。
输出格式
Print the maximum possible beauty of k shelves in the new office.
输出新办公室中 k 个书架所能达到的最大美观度。
输入输出样例
输入#1
10 4 9 14 28 1 7 13 15 29 2 31
输出#1
24
输入#2
7 3 3 14 15 92 65 35 89
输出#2
64
说明/提示
In the first example you can split the books as follows:
(9 + 14 + 28 + 1 + 7) \\& (13 + 15) \\& (29 + 2) \\& (31) = 24.In the second example you can split the books as follows:
(3 + 14 + 15 + 92) \\& (65) \\& (35 + 89) = 64.在第一个例子中,你可以将书籍按如下方式分组:
(9 + 14 + 28 + 1 + 7) \\& (13 + 15) \\& (29 + 2) \\& (31) = 24.在第二个例子中,你可以将书籍按如下方式分组:
(3 + 14 + 15 + 92) \\& (65) \\& (35 + 89) = 64.输入解题思路,AI测评打分。不知道怎么写?