Some exercises of dynamic programming

1. Change subject class Solution { public int coinChange(int[] coins, int amount) { int n = coins.length; int[] arr = new int[amount + 1];// 0..amount // Define initial conditions arr[0] = 0; for(int i = 1; i <= amount; i++) { // Find arr[i] arr[i] = Integer.MAX_VALUE; ...

Posted by nagrgk on Mon, 21 Feb 2022 07:31:36 +0100

Educational Codeforces Round 108 (Rated for Div. 2)A~D

Foreword: making A, B, D and C has been timeout, and I didn't think of how to optimize it. Rating: 1153 + 146 -- > 1299 (green) Don't talk about the problem, just talk about the solution and code. A. Red and Blue Beans   topic type: greed    analysis: if r is less than B, try to replace 1 with more, so calculate the differenc ...

Posted by integravtec on Sun, 20 Feb 2022 08:12:36 +0100

[Luogu] P1608 path statistics

Title address: https://www.luogu.com.cn/problem/P1608 Title Description: The staff quality of "RP restaurant" is not general. After calculating the same phone number, they are ready to let HZH and TZY deliver fast food. They draw a map of the city they live in. It is known that on their map, there are ...

Posted by gio2k on Sun, 20 Feb 2022 05:44:27 +0100

[recent force buckle] word split + merge interval + linked list sorting + adjust the array order so that the odd number precedes the even number

Word splitting (medium) dynamic programming ”Whether leetcode "can be composed and decomposed into - whether" l "is stored in the dictionary and subsequent substrings can be composed when the step size is 1, etc; When the step size is 2, "le" is stored in the dictionary and subsequent substrings can be compose ...

Posted by shorty114 on Sun, 20 Feb 2022 04:15:26 +0100

Longest ascending subsequence model for dynamic programming

preface Let's first analyze the original LIS problem with Yan dp analysis Strange thief Kidd's glider wing Title Transfer door We can start at any point, and there are two directions: left and right. We have to make the most of the buildings we pass Solution idea: let's take a look at the board problem of the longest body sequence whe ...

Posted by j007w on Sat, 19 Feb 2022 21:45:40 +0100

[LeetCode] fully understand the knapsack problem

0. Origin 0-1 knapsack: max min problem Concept: there are N items in total. The weight of item I (I starts from 1) is w[i], and the value is v[i]. When the total weight does not exceed the upper limit W of the backpack, what is the maximum value that can be loaded into the backpack? Idea: define a two-dimensional array dp to store the ...

Posted by juschillin on Sat, 19 Feb 2022 01:13:37 +0100

(codeforces - 149d) colouring brackets (interval DP)

Title Link: https://codeforces.com/problemset/problem/149/D Meaning: Given a string s, it is a legal sequence of parentheses. We intend to dye this bracket sequence with the following requirements: There are three conditions for each character: no dyeing, red dyeing and blue dyeingEach pair of matching parentheses has and only one character ...

Posted by polybiosis on Fri, 18 Feb 2022 16:01:13 +0100

Luogu P1896 [SCOI2005] mutual non aggression (shape pressure dp)

Title Description Title address: P1896 [SCOI2005] mutual non aggression In N × There are K kings in N's chessboard so that they don't attack each other. How many placement schemes are there. The king can attack one grid in its upper, lower, left, lower, left, lower, right, upper, right and lower eight directions, a total of 8 grids. I ...

Posted by lilRachie on Fri, 18 Feb 2022 08:03:58 +0100

SDNU_2020Shenyang_Qualification problem solution

C Gym - 102822D analysis: The answer is monotonous and can be divided into two points. Then the focus is on the writing of the judgment function. Let's assume that the answer is X. because this question needs to reduce the bomb by - 1 before it explodes, it's very awkward. Let's first consider the case that the bomb explodes when it reaches 0. ...

Posted by jhuaraya on Fri, 18 Feb 2022 07:42:23 +0100

LeetCode: Home robbery~~ Dynamic finishing

[1. House on the street, happy thief No. 1] 198. House raiding (medium) You are a professional thief who plans to steal houses along the street. There is a certain amount of cash hidden in each room. The only restrictive factor affecting your theft is that the adjacent houses are equipped with interconnected anti-theft systems. If two adjacen ...

Posted by thipse_rahul on Thu, 17 Feb 2022 22:53:26 +0100