-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathD.cpp
51 lines (37 loc) · 852 Bytes
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll k, n, ara[55], cs[55], dp[55][55];
ll check(ll msk, ll pos, ll part)
{
if(pos > n)
return part > k;
if(part > k)
return 0;
ll &ret = dp[pos][part];
if(ret != -1)
return ret;
ll rt = 0;
for(ll i = pos; i <= n; i++) {
ll sm = cs[i] - cs[pos - 1];
if( (sm & msk) == msk)
rt |= check(msk, i + 1, part + 1);
}
return ret = rt;
}
int main()
{
cin >> n >> k;
for(ll i = 1; i <= n; i++)
cin >> ara[i];
for(ll i = 1; i <= n; i++)
cs[i] = ara[i] + cs[i - 1];
ll ans = 0;
for(ll i = 55; i >= 0; i--) {
memset(dp, -1, sizeof(dp));
if(check(ans | (1LL << i), 1, 1) )
ans |= (1LL << i);
}
cout << ans << endl;
return 0;
}