(())()(()) ((())()(())()(()))

Slides:



Advertisements
Similar presentations
Towers of Hanoi Move n (4) disks from pole A to pole C such that a disk is never put on a smaller disk A BC ABC.
Advertisements

CS 206 Introduction to Computer Science II 02 / 27 / 2009 Instructor: Michael Eckmann.
Recursion CS 367 – Introduction to Data Structures.
BackTracking Algorithms
1 Parallel Parentheses Matching Plus Some Applications.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
Introduction to Bioinformatics Algorithms Divide & Conquer Algorithms.
I couldn’t think of anything to put here. So have a cow. Or two.
Graph Theory, DFS & BFS Kelly Choi What is a graph? A set of vertices and edges –Directed/Undirected –Weighted/Unweighted –Cyclic/Acyclic.
CSE 380 – Computer Game Programming Pathfinding AI
Semester 10 Time sure flies.. PotW Solution One possible solution is to randomly search the grid: o At each point in your search, look at the (up to four)
Divide-and-Conquer Recursive in structure –Divide the problem into several smaller sub-problems that are similar to the original but smaller in size –Conquer.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
3.12 ≠ π What an inspiring title. PotW Solution - Bovinekiin int stall = 0; for (int i = 0; i calcGreedy(best)) { best = new ArrayList (cur); // update.
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Tyler Robison Summer
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Dan Grossman Spring 2010.
All Pairs Shortest Paths and Floyd-Warshall Algorithm CLRS 25.2
USACOW: The Aftermath. PotW Solution Scanner s = new Scanner(System.in); int n = s.nextInt(), k = s.nextInt(), x = 0; for (int i = 0; i < n; i++) x ^=
COS 126 – Atomic Theory of Matter. Atomic Theory Overview Brownian Motion Random collision of molecules Displacement over time fits a Gaussian distribution.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
COS 126 – Atomic Theory of Matter. Announcements Project – due Friday (1/12) midnight TA Office Hours this week (check website) Lab Help (Mon-Fri 7pm-9pm)
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 08 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 02 / 25 / 2009 Instructor: Michael Eckmann.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Minimum Spanning Trees
More Dynamic Programming Floyd-Warshall Algorithm.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Fundamentals of Algorithms MCS - 2 Lecture # 7
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
1 Online algorithms Typically when we solve problems and design algorithms we assume that we know all the data a priori. However in many practical situations.
Dynamic Programming. What is dynamic programming? Break problem into subproblems Work backwards Can use ‘recursion’ ‘Programming’ - a mathematical term.
Houyang 3/25/13. USACO March Contest Congrats to Johnny Ho for scoring over 900 points in the Gold Division o 7th place in US Kudos to Jonathan Uesato.
Computer Science Club It is easier to change the specification to fit the program than vice versa.
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
Happy Birthday Julia Courier New. USACO December Contest - Congratulations to Jon+Julia+Andy for promoting to gold And Johnny - 2th place in gold among.
Please sign in on the sign up sheet MTH Computer Science Club.
Public void main What do you call something that’s not static?
Algorithm Paradigms High Level Approach To solving a Class of Problems.
CPS120: Introduction to Computer Science Operations Lecture 9.
CSC 211 Data Structures Lecture 13
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
Dynamic Programming Louis Siu What is Dynamic Programming (DP)? Not a single algorithm A technique for speeding up algorithms (making use of.
Exam Format  90 Total Points  60 Points Writing Programs  25 Points Tracing Code/Algorithms and determining results  5 Points Short Answer  Similar.
CSE373: Data Structures & Algorithms Lecture 22: The P vs. NP question, NP-Completeness Lauren Milne Summer 2015.
Break; return; // to school :’(. PotW Solution Problem recap: Write a Befunge program that prints out a Brain**** program that prints out a HQ9+ program.
Stacks and Queues. Announcements USACO Open competition results are out o Congrats to Johnny for scoring 2nd in the US USACO Finalists are also announced.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Algorithm Design Methods (II) Fall 2003 CSE, POSTECH.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Selection Sort Sorts an array by repeatedly finding the smallest.
Comp. Genomics Recitation 10 Clustering and analysis of microarrays.
Where’s the title? You gotta search for it!. PotW Solution String s = new Scanner(System.in).next(); int[] prev = new int[s.length() * 2 + 2]; Arrays.fill(prev,
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
The Manhattan Tourist Problem Shane Wood 4/29/08 CS 329E.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Searching Topics Sequential Search Binary Search.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture nine Dr. Hamdy M. Mousa.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
NAME THAT ALGORITHM #2 HERE ARE SOME PROBLEMS. SOLVE THEM. GL HF.
Week 13: Searching and Sorting
13 Text Processing Hongfei Yan June 1, 2016.
CS 2308 Exam I Review.
Dynamic Programming.
Dynamic Programming.
CSE 5290: Algorithms for Bioinformatics Fall 2009
Time Complexity and the divide and conquer strategy
Presentation transcript:

(())()(()) ((())()(())()(())) USACO (())()(()) ((())()(())()(()))

USACO November Contest The first USACO competition was last week. Lynbrook had a very strong performance as a whole Congratulations to Andy Wang (1000), Raphael Chang (933), and Edward Lee (867) for promoting to Silver Kudos to Johnny Ho (875) for scoring highest out of the US seniors on Gold Congratz to Steven Hao (938) for proving that he can O(n^2) bash problems Good job to the random 5th grader who got a perfect on Silver Full results and problems are at usaco.org

Bronze Contest: "Typo" Input: an arbitrary string of parentheses of length n, n < 100,000 Output: the number of ways you can flip exactly one of the parentheses to make the string balanced (not necessarily positive) Example: (((()) answer = 3 change either the 2nd, 3rd, or 4th parens Solution: Prefix sums The stuff we covered on the Halloween PotW

Bronze Contest: "Typo" Figure out which type of parentheses is in excess (kind of like a limiting reaction) (((()): 4 ('s, 2 )'s You should convert one of the ('s Orient it so that there are too many )'s instead of ('s Reversing/flipping the string does not change answer (((()) turns into (()))) Now you should convert one of the )'s Convert parentheses into numbers (()))) turns into {+1, +1, -1, -1, -1, -1} Take prefix sums {1, 2, 1, 0, -1, -2} A ) can be converted if and only if it lands at or before the first negative prefix sum

Silver/Gold Contest: "Balanced Cow Breeds" Input: an arbitrary string of parentheses of length n, n < 1000 Output: the number of ways you can color each parenthesis such that each color forms its own balanced string of parentheses Example: (()) (()) Solution: Dynamic programming The stuff we were just about to cover :(

Silver/Gold Contest: "Balanced Cow Breeds" Use recursion. int recurse(int index, int nestA, int nestB) If nextA or nestB become negative, quit immediately If index reaches the end of the string, return 1 if and only if nestA == 0 and nestB == 0 Otherwise, you can color index in 2 ways. You can change this to a 2D DP state nestB can be calculated from index and nestA This makes your algorithm use O(N^2) memory The algorithm visits O(N^2) states, each in constant time, for overall O(N^2)

"Concurrently Balanced Strings" K strings of parentheses, each of length N. Count the number of ranges (a, b) satisfying: For any of the K strings, the substring from a to b is a balanced string of parentheses. K <= 10, N <= 50 000 Example K = 3, N = 14, Answer: 3 N is large, need faster than quadratic. N is only 50 000 A good N^2 may pass 60 - 90% of the test cases Similar for Gold Problem 3. s_1 = )()((())))(()) s_2 = ()(()()()((()) s_3 = )))(()()))(())

"Concurrently Balanced Strings" Consider a single string. (Let K = 1) Compute for each prefix of the string its "sum" Sum of a string is # left parens - # right parens. sums[i] is the score of the prefix ending at index i. We can check if a substring from A to B is balanced. Sum of this substring is sums[B] - sums[A] This must be 0, so sums[A] == sums[B] For all A < C < B, sums[C] >= sums[A] Iterate over B Count the number of possible A. Also keep track of the negative condition. Use a map for O(n log n) Store K sums instead of 1 for original problem Steven's Code (Expertly uses map<int, int>) http://pastebin.com/rLSJwN9Y

In summary Getting partial credit by O(n^2) bashing O(nlogn) problems is a highly effective strategy Silver/bronze problems are all fairly standard Dynamic programming Graph theory (Dijkstra’s, BFS, DFS) Greedy Sorting Silver/bronze contestants have to be very careful to pass Test on both small and large test cases Now just pray that we don’t have any more problems about parentheses

PotW Last week's PotW is extended The one about Karen's sleeping habits The problem remains largely unsolved Hints for Subtask 3, where N <= 100000 Try all possible rooms as centers Try the rooms in a specific order depth-first search Avoid recomputing the sum of distances to other rooms Imagine moving the center from one room to an adjacent room What needs to be precomputed?