2022 Blue Bridge Cup learning - 7 greedy

Examples 1. Stock trading Title Description Given an array with length N, the ith number in the array represents the price of a given stock on day i. Design an algorithm to calculate the maximum profit you can make. You can complete as many transactions as possible (buying and selling a stock multiple times). Note: you cannot participate in ...

Posted by szms on Wed, 02 Feb 2022 05:33:14 +0100

Implementation, connection and difference of Prim & Dijkstra & Floyd algorithm && using Floyd algorithm to find sub short path

Implementation, connection and difference of prim & Dijkstra & Floyd algorithm && using Floyd algorithm to find sub short path catalogue Prim & Dijkstra L & Floyd, these algorithms are actually a handsome group, that is, the data structure class is too disgusting (I know everything), and I don't really realize the b ...

Posted by frosty1433 on Sun, 30 Jan 2022 14:12:19 +0100

LeetCode 55.45. Jumping game I & II (greed)

Title Link: 55. Jumping game I Title details: Given a nonnegative integer array of , nums, you are initially at the , first subscript of the array. Each element in the array represents the maximum length you can jump at that position. Judge whether you can reach the last subscript. Example 1: Input: num = [2,3,1,1,4] Output: tru ...

Posted by shinyjoy on Mon, 17 Jan 2022 17:14:27 +0100

D. Binary Spiders (thinking + dictionary tree)

D. Binary Spiders [Link](Problem - D - Codeforces) meaning of the title Here you are n n n numbers and one k k k. How many numbers can you choose at most and meet the XOR between any ...

Posted by titel on Thu, 13 Jan 2022 14:10:09 +0100

LeetCode game 275

5976. Check whether each row and column contain all integers Title Description: give you a \ (n \times n \) matrix to judge whether each row and column contain all integers from \ (1\sim n \), which returns true, otherwise it returns false. Idea: directly simulate according to the meaning of the topic Time complexity: \ (O(n^2) \) Reference cod ...

Posted by illuz1on on Sun, 09 Jan 2022 07:34:57 +0100

[data structure and algorithm] in-depth analysis of the solution idea and algorithm example of "stone game VI"

1, Title Requirements Alice and Bob play a game in turn. Alice takes the lead. There are n stones in a pile of stones. When it's a player's turn, he can remove a stone and get the value of the stone. Alice and Bob have different criteria for the value of stones. Both sides know each other's criteria.Give you two integer arrays of length n, ali ...

Posted by yuan22m on Mon, 03 Jan 2022 22:42:33 +0100

❤️ "Disgusting work" a blog takes you to master the "five core algorithms" ❤️

catalogue 1, Divide and conquer Ideological principle Specific steps Example 1 Algorithm conclusion 2, Dynamic programming algorithm Ideological principle Specific steps Algorithm implementation Algorithm conclusion 3, Backtracking algorithm         Algorithmic thought         Basic steps         Example 2         Algorithm imp ...

Posted by miraclewhipkey on Mon, 03 Jan 2022 07:23:48 +0100

3 personal training summary

Red wine competition Title A: Title Link: Click here to transfer Meaning: Given n non decreasing numbers, you are required to change a bit of a number so that it does not form a non decreasing sequence. If Impossible cannot be output Idea: For simulation, enumerating two adjacent numbers is still legal if the first bit of the previous number ...

Posted by FredAt on Fri, 31 Dec 2021 14:14:47 +0100

2021.08. 09 [popularization group] simulation group C competition summary

2021.08. 09 [popularization group] simulation group C competition summary Write before: Today's exam is average. I didn't do very well. Continue to work hard next time! 😢😢😢 The mistake of this competition is that I didn't seriously read the meaning of the topic. Next time, I will continue to work hard! ok, let's start summarizing! ...

Posted by crosbystillsnas on Sun, 26 Dec 2021 17:48:26 +0100

Algorithm analysis and Design -- greedy algorithm "activity scheduling", "knapsack problem" and "Huffman coding"

1, Basic elements of greedy algorithm As the name suggests, greedy algorithms always make the best choice at present. In other words, the greedy algorithm does not consider the overall optimization, and its choice is only the local optimal solution in a sense. The problems that can be solved by greedy algorithm generally have the follow ...

Posted by jonnypixel on Thu, 23 Dec 2021 18:06:47 +0100