#include <bits/stdc++.h>
using
namespace
std;
int
maximumAND(
int
arr[],
int
n,
int
m)
{
int
tot = 1 << n;
int
mx = 0;
for
(
int
bm = 0; bm < tot; bm++) {
int
andans = 0;
int
count = 0;
for
(
int
i = 0; i < n; ++i) {
if
((bm >> i) & 1) {
if
(count == 0) {
andans = arr[i];
}
else
{
andans = andans & arr[i];
}
count++;
}
}
if
(count == (m + 1)) {
mx = max(mx, andans);
}
}
return
mx;
}
int
main()
{
int
arr[] = { 1, 2, 3, 4 };
int
N =
sizeof
(arr) /
sizeof
(arr[0]);
int
M = 2;
cout << maximumAND(arr, N, M);
return
0;
}
0 comments:
Post a Comment