A set S of integers is valid, meaning that any subset subS of S has Fun(SubS)! =X, where X is a fixed integer, Fun(A) is defined as follows:
A is a set of integers. Suppose there are n elements in A, which are a0, a1, a2,..., an-1, then define: Fun(A)=a0 or a1 or... or an-1; Fun({}) = 0, that is, the function value of the empty set is 0. Among them, or is the or operation.
Now give you a set Y and integer X values, ask at least how many elements can be removed from set Y to make set Y valid?
For example: Y = {1,2,4}, X=7; obviously the current Y is not legal because 1 or 2 or 4 = 7, but after removing any element, Y will be legal. So, the answer is 1.
Input
The first line contains two integers N, X, where N is the number of elements in the Y set, X is as described in the title, and 1<=N<=50, 1<=X<=1,000,000,000. After N lines, each line contains an integer yi, that is, the ith element in the set Y, and 1<=yi<=1,000,000,000.
Output
An integer representing the minimum number of elements to delete.
Input example
5 7 1 2 4 7 8
Output example
2
Note that it is an arbitrary subset, then first find out all the elements that may get x, and finally find the contribution value of each element
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF 0x3f3f3f3f #define mem(a) ((a,0,sizeof(a))) typedef long long ll; ll a[55],b[55],res[55],n,x,ans,y,cnt=100; int top=0; int main() { scanf("%lld%lld",&n,&x); years = x; while (years) { a[top ++]=ans% 2 ; years /= 2 ; } for(int i=0;i<n;i++) { scanf("%lld",&y); if((y|x)!=x) continue; int top=0; while(y) { if(y&1) b[top]++; and /= 2 ; top++; } } for(int i=0;i<=50;i++) if(a[i]) cnt=min(cnt,b[i]); printf("%d\n",cnt); return 0; }