Download presentation
Presentation is loading. Please wait.
Published byWillis Gibbs Modified over 9 years ago
1
Happy Birthday Julia Courier New
2
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
3
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
4
More Bitwise Operations Shift left, Shift right x = 13 x: 00001101 x >> 1: 00000110 x >> 2: 00000011 x >> 3: 00000001 x >> 4: 00000000 x << 1: 00011010 x << 2: 00110100 x << 3: 01101000 x << 4: 11010000
5
What's the point?? Compute the i-th bit of an int. Ex: x = 69 x: 01000101 ^ 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!!
6
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.
7
BITMASK i & -i gives you the least significant set bit: i: 00011010 -i: 11100110 i&-i: 00000010 This is because -i = ~i + 1, where ~ flips all bits ~i: 11110101 ~i+1: 11110110
8
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 3 111 110 011 Sample Output: 01110
9
POTW Bounds 25 pts (apply brute force): N <= 4 35 pts (optimized brute force): N <= 8 45 pts (apply bitmask dp): N <= 16
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.