110 likes | 208 Views
boolean lessThanThree ;. Defaults to false. PotW Solution - Compression. int dp ( int i , int cnt ) { if ( cnt > lim ) return (1 << 29); if ( i == n) return 0; if ( mem [ i ][ cnt ] != -1) return mem [ i ][ cnt ]; mem [ i ][ cnt ] = 1 << 29; for ( int j = i + 1; j <= n; ++j) {
E N D
booleanlessThanThree; Defaults to false.
PotW Solution - Compression intdp(inti, intcnt) { if (cnt > lim) return (1 << 29); if (i == n) return 0; if (mem[i][cnt] != -1) return mem[i][cnt]; mem[i][cnt] = 1 << 29; for (int j = i + 1; j <= n; ++j) { int mid = (i + j) / 2, sum = 0; for (int k = i; k < j; ++k) { sum += abs(arr[k].val - arr[mid].val); } intposs = sum + dp(j, cnt + 1); if (poss < mem[i][cnt]) { mem[i][cnt] = poss; next[i][cnt] = j; } } return mem[i][cnt]; } Full source code at http://ideone.com/iC4F6!
Harker Invitational! • March 17th, 8:30am - 3:30pm • Like Gunn and other ProCo-likes • Teams of up to 3 compete in a 1.5 hour round, submit answers online, etc. • ~APCS-level problems • There will be prizes! (no idea what they are though) • And PotW credit! • There will also be a half-hour challenge round • Individuals who complete the challenge problem are entered into a raffle for a $300 Silicon Valley Driving School gift certificate • Register at http://bit.ly/harkerproco12
Harker Invitational (cont.) Tentative Schedule: • 8:30-9:30 Check-in • 9:30-10:30 Speaker • 10:30-10:40 Break • 10:40-11:00 Diagnostics/Introduction to competition infrastructure • 11:00-12:30 Competition • 12:30-1:45 Lunch • 1:45-2:00 Set-up for Challenge Round • 2:00-2:30 Challenge Round • 2:30-3:00 Awards and Raffle
Reminders! • Gunn Programming Contest is Feb. 25, 9AM – 3PM • During break! • Register at http://bit.ly/gunnproco12 • Stanford ProCo is May 19 • Details TBA
About ProCo-likes • Cooperation, time management are key • Typically only one laptop per team allowed for coding • Write your programs correctly the first time! • Problems divided into 3 difficulty levels: 2, 5, and 9-point problems • 2-point problems are typically quite trivial/straight-forward • 5-point problems take some thinking/planning (about bronze-silver USACO level) • 9-point problems can be quite challenging (at or a little below USACO Gold level?) • Find the most efficient way for your team to divide up the problems!
Harker 2011 #2.1: “Jaded J’s” • Print out the first seven presidents of the United States. • Sample input: Not applicable • Sample output: George Washington John Adams Thomas Jefferson James Madison James Monroe John Quincy Adams Andrew Jackson
#5.4: “Wordy Wordsearch” • Given a 10x10 matrix of lowercase characters, and a list of 10 words (1-10 characters), for each word output “yes” if the word is found in the word search and “no” if it isn’t. • Sample input: Sample output: aaaaaaaaaa yes bbbbbbbbbb yes ccccccccccyes ddddddddddyes eeeeeeeeeeyes aaaaaaaaaayes bbbbbbbbbbyes ccccccccccyes ddddddddddyes eeeeeeeeeeyes a ab abc abcd abcde e ed edc edcb edcba
Wordy Wordsearch (cont.) • Simply search (in all 8 directions) • Implementation is trickier than coming up with the method itself • Store wordsearch in a 2D array • Iterate through characters and compare to first letters of each word in list • Check in 8 directions each time you find a potential start of a word • Might be useful to use nested for-loops with “xDir” and “yDir” looping from -1 to 1, skip xDir==0 && yDir==0 case, to save lines of code
PotW – Who’s the Boss?( Harker Invitational 2011) • Determine the ancestors of a node in an organization graph. Given a list of employee to boss relationships and a list of queries, determine which of the queries must be satisfied. Each organizational line is composed of one team: the first element will be the number of employees in the group, the first name will be the boss, and each following name will be the direct employees. Each query is composed of two people: X and then Y. Determine if X must obey Y. • The input is guaranteed to be valid: there will be no cyclic relationships, and all names will correspond properly. • # of employees < 1000 • # of queries < 1000 • Worth 25 points
Who’s the Boss? (cont.) • Sample Input:4 (# of groups)2 BigBoss Amy Fred3 Amy Wilson Stoker Bubba4 Wilson James Marc Tim Alan2 Fred Wilma Dino3 (# of queries)Alan DinoAlan BigBossWilson James • Sample Output:noyesno