博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 981D Bookshelves
阅读量:5322 次
发布时间:2019-06-14

本文共 2051 字,大约阅读时间需要 6 分钟。

Discription

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 kkbookshelves. He decided that the beauty of the kk shelves is the  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 kk shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty.

Input

The first line contains two integers nn and kk (1kn501≤k≤n≤50) — the number of books and the number of shelves in the new office.

The second line contains nn integers a1,a2,ana1,a2,…an, (0<ai<2500<ai<250) — the prices of the books in the order they stand on the old shelf.

Output

Print the maximum possible beauty of kk shelves in the new office.

Examples

Input
10 4 9 14 28 1 7 13 15 29 2 31
Output
24
Input
7 3 3 14 15 92 65 35 89
Output
64

Note

In the first example you can split the books as follows:

 

(9+14+28+1+7)&(13+15)&(29+2)&(31)=24.(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.
 
 
 
    不难想到从高位到低位贪心,根据字段和的sum的子集里是否有当前贪心的ans,来判断可以转移的点对,跑一遍类dp就行了。
 
#include
#define ll long longusing namespace std;const int maxn=65;ll ci[maxn],sum[maxn],ans;bool can[maxn][maxn];int n,k;inline bool solve(){ memset(can,0,sizeof(can)); can[0][0]=1; for(int i=1;i<=n;i++) for(int j=0;j
>sum[i],sum[i]+=sum[i-1]; for(int i=60;i>=0;i--){ ans|=ci[i]; if(!solve()) ans^=ci[i]; } cout<
<

  

 

转载于:https://www.cnblogs.com/JYYHH/p/9108942.html

你可能感兴趣的文章
如何使用USBWebserver在本机快速建立网站测试环境
查看>>
jquery-jqzoom 插件 用例
查看>>
查看oracle数据库的连接数以及用户
查看>>
三.野指针和free
查看>>
python tkinter GUI绘制,以及点击更新显示图片
查看>>
Spring面试题
查看>>
C语言栈的实现
查看>>
SRM 628 DIV2
查看>>
2018-2019-2 20165314『网络对抗技术』Exp5:MSF基础应用
查看>>
SecureCRT的使用方法和技巧(详细使用教程)
查看>>
自建数据源(RSO2)、及数据源增强
查看>>
2018icpc徐州OnlineA Hard to prepare
查看>>
使用命令创建数据库和表
查看>>
【转】redo与undo
查看>>
安卓当中的线程和每秒刷一次
查看>>
wpf样式绑定 行为绑定 事件关联 路由事件实例
查看>>
TCL:表格(xls)中写入数据
查看>>
Oracle事务
查看>>
String类中的equals方法总结(转载)
查看>>
标识符
查看>>