25 01 backpack (maximum capacity type)

Dynamic programming problem solving steps 1. Clarify the meaning of dp array subscript and content 2. Determine recurrence formula 3. Array initialization 4. Definite push sequence 5. Verify the formula 01 Backpack Recurrence formula: dp[j] = max(dp[j], dp[j - weight[i]] + value[i]); j stands for a backpack with a capacity of j, whic ...

Added by Janus13 on Fri, 14 Jan 2022 11:17:09 +0200

Introduction to dynamic programming (knapsack problems such as 0-1 knapsack)

Basic idea of dynamic programming Understand the basic idea of dynamic programming Determine state variables (functions)Determine the state transition equation (recursive relationship)Determine boundary Various knapsack problem contents, ideas, examples and code implementation Basic 0-1 knapsack problem The basic idea of 0-1 knapsack probl ...

Added by Haggen on Thu, 13 Jan 2022 18:23:28 +0200

Li Kou 904 - fruit basket (dynamic programming)

Title (medium) You are visiting a farm where a row of fruit trees are planted from left to right. These trees are represented by an integer array of fruits, where fruits[i] is the fruit species on the ith tree. You want to collect as many fruits as possible. However, the owner of the farm has set some strict rules. You must pick fruit accordi ...

Added by hypuk on Wed, 12 Jan 2022 20:29:32 +0200

LeetCode 32. Longest valid bracket

Topic Overview: Title link: Ask me to do the problem Problem 1. Unpassable Violence Algorithms _To be honest, the first thing I thought of was this method, but it would exceed the time limit. _Its idea is simple, two-tier loops find each substring, and then use the stack to determine if each substring is a valid substring, which is simpler ...

Added by tinyang on Wed, 12 Jan 2022 19:16:39 +0200

Algorithmic Learning-Backpack Problem

1.01 Backpack Problem There are N items and a V-pack. The cost of putting item I is c[i], and the value is w[i]. Seek which items to put in your backpack to maximize the total value. The two-dimensional dynamic equation for the 01 knapsack problem is given directly: f[i][j]=max(f[i-1][j],f[j-c[i]]+w[i]); How do you understand that? Imagi ...

Added by dey.souvik007 on Tue, 11 Jan 2022 19:39:28 +0200

[PAT (Basic Level) Practice] - [find element] 1028

I. [Topic difficulty] Class B II. [Title No.] 1028 census (20 points) III. [Title Description] A census was conducted in a town and the birthdays of all residents were obtained. Now please write a program to find out the oldest and youngest people in the town.Here, ensure that each entered date is legal, but not necessarily reasonable ...

Added by phprocker on Sat, 08 Jan 2022 11:17:34 +0200

Gray code / 1046 The weight of the last stone

This problem is a simulation. I know that the solution must use bit operation, but it won't be. It's uncomfortable. Record my stupid thinking than simulation (java takes 41ms, really slow), and then calculate honestly. Idea: 1. First of all, there is an interesting rule for gray codes, that is, the first n gray codes of n+1 bits are positi ...

Added by chelsea7 on Sat, 08 Jan 2022 10:21:34 +0200

[CF936D]World of Tank

subject Portal to CF thinking The point is to find out what the operation of the tank should be. For example, we can easily find that if you destroy an obstacle, you should drive over its ruins. However, what is more important and more difficult to find is that you should not change lanes before walking to the ruins. Why? Suppose you chang ...

Added by luxluxlux on Sat, 08 Jan 2022 09:45:33 +0200

[data structure and algorithm] in-depth analysis of the solution idea and algorithm example of "different binary search tree II"

1, Title Requirements Give you an integer n, please generate and return all different binary search trees composed of N nodes with different node values from 1 to N, and you can return the answers in any order.Example 1: Input: n = 3 Output:[[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]] Example 2: Input: n = 1 ...

Added by waiwai933 on Thu, 06 Jan 2022 08:00:17 +0200

Codeforces Good Bye 2021: 2022 is NEAR ABCDE

A. Integer Diversity Count the number of figures with different absolute values in all figures. Only when the number of absolute values is less than 2 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const int N=200100; int n,m,t; int w[N]; int cw[N]; int main(){ cin>>t; while(t--) ...

Added by jibosh on Wed, 05 Jan 2022 03:22:05 +0200