Bitwise enumeration from high to low, greedy. If the bit fill 1 than fill 0 result excellent and fill 1 will not exceed the M limit, then fill 1, otherwise fill 0
1 /*by Silvern*/2#include <iostream>3#include <cstring>4#include <cstdio>5#include <cmath>6 using namespacestd;7 Const intmxn=100020;8 intn,m;9 intp[ *];Ten intOP[MXN],A[MXN]; One intans=0; A intProintx) { - for(intI=1; i<=n;i++){ - if(op[i]==1) x=x&A[i]; the Else if(op[i]==2) x=x|A[i]; - Elsex=x^A[i]; - } - returnx; + } - intMain () { +scanf"%d%d",&n,&m); A inti,j; at Charc[5]; - for(i=1; i<=n;i++){ -scanf"%s%d",c,&a[i]); - if(c[0]=='A') op[i]=1; - Else if(c[0]=='O') op[i]=2; - Elseop[i]=3; in } - for(i=0; i<= -; i++) p[i]=1<<i; to for(i= -; i>=0; i--){ + if(Ans+ (1<<i) > m)Continue;//can only fill 0 - if(Pro (1<<i) > Pro (0)) ans+= (1<<i); the } *printf"%d\n", Pro (ans)); $ return 0;Panax Notoginseng}
Rokua P2114 Get up difficulty syndrome