Greedy algorithm of algorithm

Greedy Algorithm Greedy algorithm (greedy algorithm) refers to the algorithm that takes the best or optimal (i.e. the most favorable) choice in each step when solving the problem, so as to lead to the best or optimal result The results obtained by greedy algorithm are not necessarily the optimal results (sometimes the optimal solution), but t ...

Posted by genesysmedia on Mon, 07 Feb 2022 10:46:26 +0100

Leetcode problem solving - Mathematics

Leetcode problem solving - Mathematics 204. Count prime Count the number of all prime numbers less than non negative integer n. (the definition of prime is very simple. If a number can only be divided by 1 and itself, then the number is prime.) Input: n = 10 Output: 4 Explanation: there are four prime numbers less than 10, They are two, 3, ...

Posted by JoCitizen on Mon, 07 Feb 2022 08:54:15 +0100

[Likou daily question] longest happy string

Li Kou daily question 20207 Topic description If the string does not contain any strings such as' aaa ',' bbb 'or' ccc 'as substrings, the string is a "happy string". Here are three integers a, b and c. please return any string s that meets all the following conditions: s is a happy string as long as possible. There are at mo ...

Posted by kailien on Mon, 07 Feb 2022 06:43:19 +0100

Clustering algorithm notes

Clustering algorithm - Kmeans 1. Unsupervised learning and clustering algorithm Supervised learning model algorithm, the sample data required by the model needs both characteristic matrix X and real label y.Unsupervised learning means that the model only needs to use the characteristic matrix X without the real label y. clustering algorithm i ...

Posted by luiddog on Mon, 07 Feb 2022 05:09:51 +0100

Number theory template and reasoning process

I Prime number 1. Determine prime number by trial division The factors of a number appear in pairs. We can judge the smaller one It should be noted that I < = sqrt (x) or I * I < = x should not be used as far as possible. First, it is to reduce the operation and second, it is to prevent exceeding the int range bool is_prime(int x) ...

Posted by trilbyfish on Sun, 06 Feb 2022 22:33:04 +0100

Pygame simple depth first algorithm generates maze

Before learning path calculation, we need a scene. We checked the maze generation method online and spent some time writing a simple maze generator The basic principle is very simple: The 2-dimensional matrix is used to represent the maze. Each node has four walls. The depth search is used to move in four directions randomly. If the node is rea ...

Posted by JADASDesigner on Sun, 06 Feb 2022 21:22:56 +0100

[daily question] game 279 weekly question - weekly game is still interesting

⭐ New pit in winter vacation -- daily question notes of code Fox ⭐ Problem solving ideas Save in groups by subscript parity and sort them separatelyGet each digit, sort, and process according to the positive and negative classification (negative numbers require the largest positive number after rearrangement, positive numbers require ...

Posted by evanesq on Sun, 06 Feb 2022 20:43:19 +0100

Simulated annealing algorithm

1, Problem description In the actual daily life, people often encounter the following problems: find the function in a given definition field X f ( x ) f(x) The optimal value corresponding ...

Posted by zero_ZX on Sun, 06 Feb 2022 04:33:48 +0100

Tree DP Exercise

The longest path of a tree Title link: The longest path of a tree Analysis: We need DP on the tree, it is difficult to represent the state. We want to find the longest path, so we draw a tree at will Code implementation: #include<iostream> using namespace std; const int N=1e4+10,M=2*N; int n,h[N],w[M],ne[M],idx=1,e[M],ans; void add ...

Posted by Plakhotnik on Sat, 05 Feb 2022 19:56:43 +0100

Algorithm and data system course notes - 9.2 linked list related topics

9. Analysis overview of linked list related topics Link to mind map Algorithm and data structure mind map Refer to the course notes of Zuo Cheng cloud system algorithm Refer to Moke network algorithm system course notes Summary of common questions: 1. Find the middle node of the linked list Meaning: It is designed to find the sp ...

Posted by gingerboy101 on Sat, 05 Feb 2022 19:01:56 +0100