![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
文章平均质量分 75
益达915
一名在读大学生,渣渣一枚,进取中...
展开
-
LeetCode | Regular Expression Matching
Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string原创 2016-08-16 10:07:17 · 213 阅读 · 0 评论 -
九度 1131 合唱队形
题目1131:合唱队形时间限制:1 秒内存限制:32 兆特殊判题:否提交:3549解决:1104题目描述:N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形。合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1, 2, …, K,他们的身高分别为T1, T2, …,原创 2016-08-25 09:59:39 · 433 阅读 · 0 评论 -
LeetCode | Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You ma原创 2016-08-25 11:19:33 · 346 阅读 · 0 评论 -
LeetCode | Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret原创 2016-08-25 16:52:40 · 276 阅读 · 0 评论 -
LeetCode | Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2016-08-26 15:58:51 · 426 阅读 · 0 评论 -
LeetCode | Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr原创 2016-08-26 15:40:18 · 493 阅读 · 0 评论 -
LeetCode | Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p原创 2016-08-26 18:03:12 · 485 阅读 · 0 评论 -
LeetCode | Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2016-08-26 20:52:35 · 468 阅读 · 0 评论 -
LeetCode | Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2016-08-26 22:12:54 · 407 阅读 · 0 评论 -
LeetCode | Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"原创 2016-08-27 00:16:54 · 428 阅读 · 0 评论 -
LeetCode | Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1原创 2016-08-24 18:13:38 · 327 阅读 · 0 评论 -
LeetCode | Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle [ [2], [3,4], [6,5,原创 2016-08-22 23:15:46 · 245 阅读 · 0 评论 -
动态规划入门 & 线性动态规划
参考文献:全国青少年信息学竞赛培训教材——复赛(陈合力 游光辉 编著)一、概念在多阶段决策的问题中,各阶段采取的决策,一般俩说是与空间或者时间相关的。决策依赖于当前状态,又随即引起状态的转移,一个决策序列就是在变化的状态中产生出来,故有动态的含义。 我们称这种解决多阶段决策最优化的过程称为动态规划方法。 例如在一个m*n的迷宫中,从左下角走到右上角 可以看原创 2016-08-04 16:35:47 · 839 阅读 · 2 评论 -
HDU | Labyrinth
Labyrinth参考博客:http://blog.csdn.net/lttree/article/details/26590299题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4826 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot原创 2016-08-04 18:26:49 · 279 阅读 · 0 评论 -
LeetCode | Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "原创 2016-08-27 11:51:48 · 510 阅读 · 0 评论 -
NOIP 2010 乌龟棋
题目描述 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物。 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数)。棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家控制一个乌龟棋子从起点出发走到终点。 乌龟棋中M张爬行卡片,分成4种不同的类型(M张卡片中不一定包含所有4种类型的卡片,见样例),每种类型的卡片上分别标有1、2、3、4四个数字之一,表示使用这种卡片后,乌龟棋子将向前爬行相应的原创 2016-08-18 17:21:00 · 351 阅读 · 0 评论 -
Subset sum Problem
给出一个集合和一个数值total,输出用哪几个数可以组出total。参考链接:http://algorithms.tutorialhorizon.com/dynamic-programming-subset-sum-problem/DP方程为 dp[i][j]=dp[i-1][j] if a[j]>jdp[i-1][j-a[j]] if a[j]<=j方程的形式同背包问题如出一辙,原创 2016-08-16 16:11:48 · 850 阅读 · 0 评论 -
UVA | Coin Change
引入Coin Changing Minimum Coins Dynamic Programming 给出N中不同金额的硬币,每种金币有无限多个。给定一个金额M,问最少需要多少个硬币可以凑成M?熟悉的朋友一看这道题就知道是完全DP,具体也没有什么好说的了,不过这里还是推一推。由Subset Sum Problem的推导我们知道,01背包其i状态完全依赖于i-1状态,在不需要还原具体解是如何的情况下,原创 2016-08-19 10:45:22 · 282 阅读 · 0 评论 -
LeetCode | Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reac原创 2016-08-20 10:40:00 · 272 阅读 · 0 评论 -
LeetCode | Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest produ原创 2016-08-10 10:04:10 · 228 阅读 · 0 评论 -
最大m子段和
问题描述给定由n个整数(可能为负数)组成的序列a1,a2,a3……an,以及一个正整数m,要求确定此序列的m个不相交子段的总和达到最大。最大子段和问题是最大m字段和问题当m=1时的特殊情形。思考过程参考文章:http://www.cnblogs.com/chuckcpc/p/dp_Max_M_Sum.html 参考文献:http://blog.163.com/sentimental_man/bl原创 2016-08-22 17:33:36 · 533 阅读 · 0 评论 -
最小编辑距离 | Minimum Edit Distance
关于两个字符串s1,s2的差别,可以通过计算他们的最小编辑距离来决定。 设A、B为两个字符串,狭义的编辑距离定义为把A转换成B需要的最少删除(删除A中一个字符)、插入(在A中插入一个字符)和替换(把A中的某个字符替换成另一个字符)的次数,用ED(A,B)来表示。直观来说,两个串互相转换需要经过的步骤越多,差异越大。对于编辑距离的状态转移较为难想。 正确的思路应当是将s1的前i位数据转换成s2的前原创 2016-08-22 22:05:21 · 1695 阅读 · 0 评论 -
LeetCode 32. Longest Valid Parentheses
问给出一串括号 ()))(())..,最长的valid括号组合有多长?(括号组合需要连续)这道题确实比较麻烦,在这里记录一下错误思路:①想到的是这道题应该可以用dp做。设dp[i][j]代表从s[i..j]中valid括号组合最大长度。然后如果:s[i] == '(' and s[j] == ')'岂不是就可以转化成dp[i+1][j-1]的问题。dp方程是dp[i][j]=dp原创 2018-02-02 22:35:52 · 125 阅读 · 0 评论