Double pointer algorithm - sum of two numbers II

Give you an integer array numbers with subscript starting from 1. The array has been arranged in non decreasing order. Please find two numbers in the array that meet the sum of addition and equal to the target number target. If the two numbers are numbers[index1] and numbers[index2] respectively, then 1 < = index1 < index2 < = numbers ...

Posted by Hobgoblin11 on Fri, 11 Feb 2022 10:01:40 +0100

Algorithm analysis and design of Beihang 2020-C2

Say at the beginning This blog only provides learning materials and my personal review. In the process of learning algorithms, the code should be typed by myself. It is not convenient to copy and paste the code directly. Copy code without harm. preface The original intention of writing this series of blogs is that the process of learning alg ...

Posted by plaggypig on Thu, 10 Feb 2022 22:33:22 +0100

[force buckle] the binary tree is transformed into the next node of the linked list binary tree. The binary tree and the path with a certain value print the binary tree into multiple lines

Brush on the buckle these days Some binary tree problems, rely on the basis (pre order traversal ~ middle order traversal ~ subsequent traversal ~ sequence traversal) to solve the problem. Of course, there are many methods to solve the problem.    [introduce the basic traversal first] Preorder traversal The first step is to ...

Posted by neller on Thu, 10 Feb 2022 03:26:03 +0100

Dynamic programming (knapsack problem)

A - upper step 2 Xiaogua wants to go up a total of N steps. Due to the special leg length of xiaogua, he can only go up 1 or 3 or 5 steps at a time. Xiaogua wants to know how many ways he can get up these n steps. Can you help him? Input An integer n (n < = 100000) in a row indicates that there are n steps in total. Output An integer i ...

Posted by cupboy on Wed, 09 Feb 2022 16:34:44 +0100

Longest incremental subsequence (LIS) dynamic programming, greedy + dichotomy (java version)

catalogue Problem Description: Dynamic programming: (n^2) java code: Greed + dichotomy: (nlongn) java code: Use of binarysearch(): Problem Description: Given a sequence, such as arr=[10, 9, 2, 5, 3, 7, 101, 18], find the longest increasing subsequence of the sequence. The longest increasing subsequence (LIS) can be solved by dynamic p ...

Posted by Jeremy_North on Tue, 08 Feb 2022 12:19:44 +0100

Code Capriccio record: binary tree (Part II)

236. Nearest common ancestor of binary tree Title Description: Train of thought analysis: Anyway, I'm still confused about recursion... More practice can only be. The thought of boss Carl can still be understood. It's really unexpected when he did it himself. The code is as follows: /** * Definition for a binary tree node. * public class ...

Posted by plouka on Sun, 06 Feb 2022 19:21:09 +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

Dynamic programming -- palindrome string series

1. Longest palindrome substring 2.    preface Dynamic programming palindrome string series has always been a pain point for me. After reading the book this morning, I thought I had fully understood it. As a result, I closed the book and knocked the code in the afternoon. I haven't finished it all afternoon. Alas, sure enough, the code ...

Posted by oscardog on Sat, 05 Feb 2022 10:48:02 +0100

Python Blue Bridge Cup dynamic planning 2 examples + supporting 1 real problem over the years

64 days from the Blue Bridge Cup, let's prepare for the blue bridge cup with Xiao Zheng Blue Bridge Cup real title link : numeric triangle         Leedcode frog jumping steps         Leedcode different paths I hereby thank the author for his on-demand broadcast, and Xiao Zheng has benefited a lot from it Article sourcehttps://cloud.ten ...

Posted by phpgeek17 on Fri, 04 Feb 2022 13:08:28 +0100

Mathematical modeling 2020B problem crossing the desert

1. Title Consider the following small games: players use a map, use the initial funds to buy a certain amount of water and food (including food and other daily necessities), start from the starting point and walk in the desert. In case of different weather on the way, you can also supplement funds or resources in mines and villages. The goal i ...

Posted by oskom on Fri, 04 Feb 2022 10:30:00 +0100