Happy Birthday Julia Courier New
USACO December Contest - Congratulations to Jon+Julia+Andy for promoting to gold And Johnny - 2th place in gold among US competitors with 2- letter-long last names. Steven beat Johnny January Contest - today is last day take it guise o potw points
Bitmasks First: bitwise operations XOR, AND, OR example: a = 18, b = 14. a ^ b = ???? a :10010 b :01110 a ^ b:11100 a | b:11110 a & b:00010
More Bitwise Operations Shift left, Shift right x = 13 x: x >> 1: x >> 2: x >> 3: x >> 4: x << 1: x << 2: x << 3: x << 4:
What's the point?? Compute the i-th bit of an int. Ex: x = 69 x: ^ 0'th bit. i'th bit of x is (x >> i) & 1 in general, x & 1 isolates its 0'th (least significant) bit. equiv. to x % 2 but faster Now we can treat an int like we do a bool array!! When we use an int like this, it's called a BITMASK!!
BITMASK what's the point?? 1) Saves memory 2) Can be indexed in an array - USEFUL WHEN DOING DP 3) Can be easily incremented; iterating a bitmask from 0 to (1 << n) generates all 2^n possible "bool arrays of length n" this can let you iterate over all subsets of a set easily - just one for loop!! also use 1 << x to calculate the x'th powers of 2 quickly.
BITMASK i & -i gives you the least significant set bit: i: i: i&-i: This is because -i = ~i + 1, where ~ flips all bits ~i: ~i+1:
POTW Given a set of N binary strings with length less than or equal to 5, find the shortest binary string that contains all of them as substrings. Sample Input Sample Output: 01110
POTW Bounds 25 pts (apply brute force): N <= 4 35 pts (optimized brute force): N <= 8 45 pts (apply bitmask dp): N <= 16