
动态规划(DP)
文章平均质量分 61
小白菜又菜
这个作者很懒,什么都没留下…
展开
-
Leetcode 312. Burst Balloons
【代码】Leetcode 312. Burst Balloons。原创 2025-03-22 19:50:36 · 654 阅读 · 0 评论 -
Leetcode 2466. Count Ways To Build Good Strings
【代码】Leetcode 2466. Count Ways To Build Good Strings。原创 2025-02-16 22:19:40 · 725 阅读 · 0 评论 -
Leetcode 1035. Uncrossed Lines
【代码】Leetcode 1035. Uncrossed Lines。原创 2025-02-16 22:09:54 · 946 阅读 · 0 评论 -
Leetcode 712. Minimum ASCII Delete Sum for Two Strings
【代码】Leetcode 712. Minimum ASCII Delete Sum for Two Strings。原创 2025-02-16 22:06:32 · 707 阅读 · 0 评论 -
Leetcode 518. Coin Change II
【代码】Leetcode 518. Coin Change II。原创 2025-02-16 21:59:48 · 260 阅读 · 0 评论 -
Leetcode 416. Partition Equal Subset Sum
【代码】Leetcode 416. Partition Equal Subset Sum。原创 2024-12-15 17:39:04 · 300 阅读 · 0 评论 -
Leetcode 1143. Longest Common Subsequence
【代码】Leetcode 1143. Longest Common Subsequence。原创 2024-07-05 21:55:11 · 1256 阅读 · 0 评论 -
Leetcode 673. Number of Longest Increasing Subsequence
【代码】Leetcode 673. Number of Longest Increasing Subsequence。原创 2024-07-05 21:48:34 · 395 阅读 · 0 评论 -
Leetcode 646. Maximum Length of Pair Chain
【代码】Leetcode 646. Maximum Length of Pair Chain。原创 2024-07-05 21:43:26 · 558 阅读 · 0 评论 -
Leetcode 516. Longest Palindromic Subsequence
【代码】Leetcode 516. Longest Palindromic Subsequence。原创 2024-07-05 21:38:29 · 581 阅读 · 0 评论 -
Leetcode 213. House Robber II
【代码】Leetcode 213. House Robber II。原创 2024-05-01 19:56:49 · 126 阅读 · 0 评论 -
Leetcode 931. Minimum Falling Path Sum
【代码】Leetcode 931. Minimum Falling Path Sum。原创 2024-04-22 14:00:57 · 499 阅读 · 0 评论 -
Leetcode 334. Increasing Triplet Subsequence
【代码】Leetcode 334. Increasing Triplet Subsequence。原创 2024-04-22 13:54:31 · 390 阅读 · 0 评论 -
Leetcode 740. Delete and Earn
【代码】Leetcode 740. Delete and Earn。原创 2024-02-18 14:04:46 · 381 阅读 · 0 评论 -
Leetcode 304. Range Sum Query 2D - Immutable
【代码】Leetcode 304. Range Sum Query 2D - Immutable。原创 2024-02-18 13:47:18 · 438 阅读 · 0 评论 -
Leetcode 198. House Robber
【代码】Leetcode 198. House Robber原创 2022-11-27 14:00:55 · 221 阅读 · 0 评论 -
Leetcode 377. Combination Sum IV
Leetcode 377. Combination Sum IV原创 2022-08-08 21:51:21 · 174 阅读 · 0 评论 -
Leetcode 152. Maximum Product Subarray
ProblemGiven an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product.The test cases are generated so that the answer will fit in a 32-bit integer.A subarray is a contiguous subseq原创 2022-05-22 17:22:44 · 205 阅读 · 0 评论 -
Leetcode 132. Palindrome Partitioning II
ProblemGiven a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.A palindrome string is a string that reads the same backward as forward.AlgorithmDP. Use dp to calculate t原创 2021-12-18 21:08:14 · 348 阅读 · 0 评论 -
Leetcode 131. Palindrome Partitioning
ProblemGiven a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.A palindrome string is a string that reads the same backward as forward.AlgorithmDP + dfs. Use dp to calcu原创 2021-12-18 20:53:09 · 343 阅读 · 0 评论 -
Leetcode 123. Best Time to Buy and Sell Stock III
ProblemYou are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete at most two transactions.Note: You may not engage in multiple transactions simultaneously (i.e.,原创 2021-10-29 20:39:20 · 224 阅读 · 0 评论 -
Leetcode 87. Scramble String
ProblemWe can scramble a string s to get a string t using the following algorithm:If the length of the string is 1, stop.If the length of the string is > 1, do the following:Split the string into two non-empty substrings at a random index, i.e., i原创 2021-01-24 16:44:31 · 149 阅读 · 0 评论 -
Leetcode 85. Maximal Rectangle
ProblemGiven a rows x cols binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.AlgorithmDynamic Programming (DP). The same problem as Leetcode 84.We decompose the problem into the largest rectangle,原创 2020-12-31 11:06:44 · 165 阅读 · 0 评论 -
Leetcode 84. Largest Rectangle in Histogram
ProblemGiven n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.AlgorithmDynamic Programming (DP). The key is to find the maximum continuous length of eac原创 2020-12-31 11:00:32 · 141 阅读 · 2 评论 -
UVa 10066 - The Twin Towers
题目:最大公共最序列。分析:dp。原创 2014-04-27 22:28:04 · 1486 阅读 · 0 评论 -
UVa 10130 - SuperSale
题目:有一个超市大甩卖,但是每个人同样的商品只能拿一件,商品有价值和重量,现在有一个顾客序列, 每个人能拿的最大重量已知,求这些顾客,能拿到的最大价值的物品和。分析:dp,01背包。看题目显然是01背包,每个物品只能取一种,每个顾客其实是一个单独的01背包过程,求和即可。注意:dp的初始化,和数据的清空。#include #include #include原创 2014-03-24 14:33:15 · 1122 阅读 · 0 评论 -
UVa 709 - Formatting Text
题目:给你一段文字,让你对文字排版,每行的最大长度有限制L,有一个对于排版格式的权值公式: P = sum((单词间空格-1)*(单词间空格-1)) 求出P最小的一种排版,F相同时输出前面的空格最少的。分析:DP。看见题目第一想到的就是利用dp,设F(i,j)是从第i个单词开始排版,到第j个单词结束的最小P原创 2014-03-26 14:59:16 · 1929 阅读 · 0 评论 -
UVa 10036 - Divisibility
题目:分析:说明:原创 2014-05-15 23:29:47 · 2946 阅读 · 0 评论 -
UVa 10069 - Distinct Subsequences
题目:求出两个串S,T,求S中字串T的原创 2014-04-27 20:39:07 · 778 阅读 · 0 评论 -
UVa 900 - Brick Wall Patterns
题目:在一个2*n的地面上铺1分析:dp。原创 2014-06-25 10:04:00 · 1244 阅读 · 0 评论 -
UVa 10404 - Bachet's Game
题目:有一堆石头,每次可以从里面取出集合M中的renyi原创 2014-05-26 21:37:33 · 1103 阅读 · 0 评论 -
UVa 11587 - Brick Game
题目:brick game是有一些连续编号的木块1~N,再给你一个若干整数构成的集合S; 两个人轮流取出集合S中存在的任意数字个木块,最后取走的人获胜,如果不能取,则对方获胜。 现在,给你一个游戏结果的序列串T,如果木块有k个,可能赢就是T[k] = W,一定输就是T[k] = L。 请你确定一个最小的集合,使得这个序列原创 2014-05-14 00:53:07 · 1599 阅读 · 0 评论 -
UVa 231 - Testing the CATCHER
题目:有一个导弹系统,在设置一个高度后,每原创 2014-06-10 21:13:47 · 835 阅读 · 0 评论 -
UVa 507 - Jill Rides Again
题目:分析:说明:原创 2014-06-11 01:39:38 · 814 阅读 · 0 评论 -
UVa 457 - Linear Cellular Automata
题目:有40个培养皿,每个培养皿中有一个数字(0-9)。最开始时20号中数字为1,其余为0。 每组输入有一个DNA programs(10个数字构成的序列),它决定每个培养皿下个时间的数字。 设培养皿i中的数字为F(i),则下次其中的数字为DNA(F(i-1)+F(i)+F(i+1)) {即,编号为F(i-1)+F(i)原创 2014-06-13 01:31:44 · 1670 阅读 · 0 评论 -
UVa 10534 - Wavio Sequence
题目:给你一串数,从里面找到yig原创 2014-06-17 08:56:56 · 811 阅读 · 0 评论 -
UVa 10723 - Cyborg Genes
题目:给你两个字符串,求一个最短的串,使得这两个串是目标串的子串。分析:DP,最大公共子序列。最长目标串的长度为两串和减去最大公共子序列。 最长目标串的数量就是所有长度相同的情况的数量加和(路径的加和) 状态f(i,j)为串str1的前i个字符原创 2014-07-28 09:11:21 · 2784 阅读 · 0 评论 -
UVa 988 - Many Paths, One Destination
题目:人生有很多选择,现在给你一些选择(0~n-1),和每个选择分支后面的其他选择序号,求选择总数。分析:dp,图论。如果某状态的后续选择个数是0个则,代表死亡,统计所有到达死亡的路径条数即可。 用一个状态数组记录到达每个选择的路径数,它等于能到达它的前驱节点的路径加和。 稀疏图,使用邻接表储存。初始是节点0的路径条数为1,代表出生。说明原创 2014-08-04 15:55:44 · 989 阅读 · 0 评论 -
UVa 624 - CD
题目:给你一些音乐的播放时间,yizhao分析:说明:原创 2014-06-23 00:21:46 · 1195 阅读 · 0 评论 -
UVa 10684 - The jackpot
题目:给你一串整数,求其中连续加和的最大值。分析:dp,最大字段和。don原创 2014-07-14 12:16:53 · 1830 阅读 · 4 评论