diff options
author | Benjamin Qi | 2020-07-20 19:17:40 -0400 |
---|---|---|
committer | Benjamin Qi | 2020-07-20 19:17:40 -0400 |
commit | cbce9826a617bcb9f44bb74c7b6a88a7d6c5c42e (patch) | |
tree | d4bec8096131c50d12fb7db3962f52bfc78b30ac | |
parent | a653aca388886e3579b485b624b265eab951c42a (diff) |
complete search w/ recursion
-rw-r--r-- | content/2_Bronze/Complete_Rec.mdx (renamed from content/2_Bronze/Gen_Perm.mdx) | 73 | ||||
-rw-r--r-- | content/2_Bronze/Intro_Complete.mdx | 33 | ||||
-rw-r--r-- | content/3_Silver/Unordered.mdx | 3 | ||||
-rw-r--r-- | content/ordering.ts | 2 |
4 files changed, 67 insertions, 44 deletions
diff --git a/content/2_Bronze/Gen_Perm.mdx b/content/2_Bronze/Complete_Rec.mdx index 239b389..3dd1aa9 100644 --- a/content/2_Bronze/Gen_Perm.mdx +++ b/content/2_Bronze/Complete_Rec.mdx @@ -1,9 +1,9 @@ --- -id: gen-perm -title: "Generating Permutations" +id: complete-rec +title: "Complete Search with Recursion" author: Darren Yao, Sam Zhang -description: "Methods to generate all permutations of an array, a common technique associated with complete search." -frequency: 1 +description: "Includes generating subsets and permutations." +frequency: 2 prerequisites: - intro-complete --- @@ -11,18 +11,39 @@ prerequisites: import { Problem } from "../models"; export const problems = { - permSam: [ - new Problem("CSES", "Creating Strings I", "1622", "Intro|Easy", false, [], "all perms of string"), - ], - ex: [ - new Problem("Bronze", "Photoshoot", "988", "Normal", false, [], ""), - ], - perm: [ - new Problem("CSES", "Chessboard and Queens", "1624", "Normal", false, [], "Recursively backtrack. See CSES book for more details."), - new Problem("Bronze", "Livestock Lineup", "965", "Hard", false, ["permutations"], ""), // 91.95 - ] + subset: [ + new Problem("CSES", "Apple Division", "1623", "Intro|Very Easy", false, ["Recursion", "Subsets"], "all $2^n$ subsets"), + ], + permSam: [ + new Problem("CSES", "Creating Strings I", "1622", "Intro|Easy", false, [], "all perms of string"), + ], + ex: [ + new Problem("Bronze", "Photoshoot", "988", "Normal", false, [], ""), + ], + back: [ + new Problem("CSES", "Chessboard and Queens", "1624", "Normal", false, [], "Recursively backtrack. See CSES book for more details."), + new Problem("CSES", "Grid Paths", "1625", "Insane", false, [], "Recursively backtrack. See CSES book for more details."), + ], + gen: [ + new Problem("Bronze", "Back & Forth", "857", "Hard", false, [], "exponential time going through all possibilities"), // 99.63 + new Problem("Bronze", "Livestock Lineup", "965", "Hard", false, ["permutations"], ""), // 91.95 + ], }; +## Generating Subsets + +<Resources> + <Resource source="CPH" title="5.1 - Generating Subsets" starred> </Resource> +</Resources> + +<Problems problems={problems.subset} /> + +## Generating Permutations + +<Resources> + <Resource source="CPH" title="5.2 - Generating Permutations" starred> </Resource> +</Resources> + <Problems problems={problems.permSam} /> <br /> @@ -33,7 +54,7 @@ A **permutation** is a reordering of a list of elements. Some problems will ask <Resource source="GFG" url="write-a-c-program-to-print-all-permutations-of-a-given-string" title="Printing all Permutations of Given String"> </Resource> </Resources> -## Lexicographical Order +### Lexicographical Order This term is mentioned quite frequently: @@ -55,7 +76,7 @@ Notice that the list starts with permutations beginning with 1 (just like a dict Generally, unless you are specifically asked to find the lexicographically smallest/largest solution, you do not need to worry about whether permutations are being generated in lexicographical order. However, the idea of lexicographical order does appear quite often in programming contest problems, and in a variety of contexts, so it is strongly recommended that you familiarize yourself with its definition. -## Checking Permutations in Lexicographical Order +### Checking Permutations in Lexicographical Order What's going to be in the `check` function depends on the problem, but it should verify whether the current permutation satisfies the constraints given in the problem. @@ -63,13 +84,13 @@ What's going to be in the `check` function depends on the problem, but it should <CPPSection> -### Method 1 +#### Method 1 ($O(N\cdot N!)$ code) <IncompleteSection /> -### Method 2 +#### Method 2 <Resources> <Resource source="Mark Nelson" title="Next Permutation" url="https://marknelson.us/posts/2002/03/01/next-permutation.html"> </Resource> @@ -121,6 +142,18 @@ public class Test { </LanguageSection> -### Problems +## Backtracking + +<Problems problems={problems.back} /> + +<Resources> + <Resource source="CPH" title="5.3, 5.4 - Backtracking, Pruning"> </Resource> +</Resources> + +No (current) bronze problem should require pruning ... + +## Problems + +<Problems problems={problems.gen} /> -<Problems problems={problems.perm} />
\ No newline at end of file +<IncompleteSection />
\ No newline at end of file diff --git a/content/2_Bronze/Intro_Complete.mdx b/content/2_Bronze/Intro_Complete.mdx index 0fc3dee..8b21022 100644 --- a/content/2_Bronze/Intro_Complete.mdx +++ b/content/2_Bronze/Intro_Complete.mdx @@ -9,31 +9,26 @@ frequency: 4 import { Problem } from "../models"; export const problems = { - easier: [ - new Problem("CSES", "Apple Division", "1623", "Intro|Very Easy", false, ["Recursion"], "all $2^n$ subsets"), + probs: [ new Problem("Bronze", "Diamond Collector", "639", "Easy", false, ["Nested Loop"], "fix the min"), // 99.9 new Problem("Bronze", "Milk Pails", "615", "Easy", false, ["Nested Loop"], "Hint: Fix the number of first-type operations you perform."), // 99.71 - new Problem("Bronze", "Bovine Genomics", "736", "Easy", false, ["Nested Loop"], ""), // 99.73 - new Problem("Bronze", "Cow Gymnastics", "963", "Easy", false, ["Nested Loop"], "Hint: Brute force over all possible pairs."), // 99.93 - new Problem("Bronze", "Where Am I?", "964", "Easy", false, [], "Hint: Brute force over all possible substrings."), // 99.48 - new Problem("Bronze", "Triangles", "1011", "Easy", false, [], "loop over the possible right angles"), // 98.02 - ], - harder: [ + new Problem("Bronze", "Bovine Genomics", "736", "Normal", false, ["Nested Loop"], ""), // 99.73 + new Problem("Bronze", "Cow Gymnastics", "963", "Normal", false, ["Nested Loop"], "Hint: Brute force over all possible pairs."), // 99.93 + new Problem("Bronze", "Where Am I?", "964", "Normal", false, [], "Hint: Brute force over all possible substrings."), // 99.48 + new Problem("Bronze", "Triangles", "1011", "Normal", false, [], "loop over the possible right angles"), // 98.02 new Problem("Bronze", "Lifeguards", "784", "Normal", false, [], "Hint: Try removing each lifeguard one at a time."), // 98.76 - new Problem("Bronze", "Photoshoot", "988", "Normal", false, [], "Hint: Figure out what exactly you're complete searching."), // 98.45 - new Problem("Bronze", "Back & Forth", "857", "Hard", false, [], "exponential time going through all possibilities"), // 99.63 - new Problem("Bronze", "Field Reduction", "641", "Hard", false, [], "Hint: For this problem, you can't do a full complete search; you have to do a reduced search."), // 91.75 new Problem("Bronze", "Circle Cross", "712", "Hard", false, [], "For every pair, check if they cross (draw small cases to figure out how). Be careful about overcounting."), // 89.6 - new Problem("Silver", "Bovine Genomics", "739", "Hard", false, [], "Brute force every substring and check if they explain spottiness."), new Problem("Bronze", "Load Balancing", "617", "Very Hard", false, [], ""), // 82.79 new Problem("Bronze", "Bull in a China Shop", "640", "Very Hard", false, [], "lots of WA on this one"), // 47.38 - new Problem("Silver", "Field Reduction", "642", "Very Hard", false, [], ""), ], }; +<!-- new Problem("Bronze", "Field Reduction", "641", "Hard", false, [], "Hint: For this problem, you can't do a full complete search; you have to do a reduced search."), // 91.75 --> + +<!-- new Problem("Silver", "Field Reduction", "642", "Very Hard", false, [], ""), --> + <Resources> - <Resource source="IUSACO" title="6 - Simulation">module is based off this</Resource> - <Resource source="CPH" title="5.1 to 5.3 - Complete Search"> </Resource> + <Resource source="IUSACO" title="6 - Complete Search">module is based off this</Resource> </Resources> <br /> @@ -111,10 +106,4 @@ A couple notes: ## Problems -### Easier - -<Problems problems={problems.easier} /> - -### Harder - -<Problems problems={problems.harder} />
\ No newline at end of file +<Problems problems={problems.probs} /> diff --git a/content/3_Silver/Unordered.mdx b/content/3_Silver/Unordered.mdx index f530ad8..4983dc3 100644 --- a/content/3_Silver/Unordered.mdx +++ b/content/3_Silver/Unordered.mdx @@ -20,7 +20,8 @@ export const problems = { standard: [ new Problem("CSES", "Sum of Two Values", "1640", "Easy", false, [], "Brute force one value by going through a[], then check if the other exists."), new Problem("Bronze", "Where Am I?", "964", "Easy", false, [], "Store all substrings in a map of <string, count>, and then find the longest length such that no substring of that length appears twice."), - new Problem("Silver", "Cities & States", "667", "Hard", false, [], "Store two maps of counts for the first two letters of a city and state code, then iterate over the cities and use the maps to efficently query for the corresponding counts."), + new Problem("Silver", "Bovine Genomics", "739", "Easy", false, [], ""), + new Problem("Silver", "Cities & States", "667", "Normal", false, [], "Store two maps of counts for the first two letters of a city and state code, then iterate over the cities and use the maps to efficently query for the corresponding counts."), ], }; diff --git a/content/ordering.ts b/content/ordering.ts index 625eb67..c0edfbc 100644 --- a/content/ordering.ts +++ b/content/ordering.ts @@ -79,7 +79,7 @@ const MODULE_ORDERING: {[key in SectionID]: Chapter[]} = { description: "Solving bronze problems by checking all possible cases in the solution space.", items: [ "intro-complete", - "gen-perm" + "complete-rec", ] }, { |