
动态规划
文章平均质量分 51
小·幸·运
你的所有努力最后都会回赠予你。
展开
-
leetcode:63. 不同路径 II----动态规划解法
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径?网格中的障碍物和空位置分别用 1 和 0 来表示。示例 1:输入:obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]输出:2解释:3x3 网格的正中间有一个障碍物。从左上角到右下角一共有 2 条不同的路径:原创 2021-02-18 17:45:20 · 191 阅读 · 0 评论 -
01背包问题详解-----动态规划
题目:给定N个项目的权重和价值(利润),将这些项目放入最大容量W的背包中,以获得背包中的最大总值(利润)。 递归解法:此时我们由这个问题得到了一个子问题通用的解决方案,来检查我得到的利润通过挑选项目或不挑选该项目这也就是选与不选的问题当我选择物品时,我需要将其从计算中移除,因为您已经对当前物品进行了处理,并通过拾取物品的重量减少了背包容量。 当我不选择物品时,我需要从计算中...原创 2019-02-10 17:39:31 · 381 阅读 · 0 评论 -
PAT甲级A1068 Find More Coins (30 分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...原创 2019-02-10 16:42:35 · 507 阅读 · 0 评论 -
PAT甲级A1045 Favorite Color Stripe (30 分)
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts...原创 2019-01-16 20:42:09 · 201 阅读 · 0 评论 -
PAT甲级A1040 Longest Symmetric String(25 分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you ...原创 2018-08-30 21:28:51 · 212 阅读 · 0 评论 -
PAT甲级A1007 Maximum Subsequence Sum (25)
Given a sequence of K integers { N~1~, N~2~, ..., N~K~ }. A continuous subsequence is defined to be { N~i~, N~i+1~, ..., N~j~ } where 1 <= i <= j <= K. The Maximum Subsequence is the continuo...原创 2018-07-24 23:12:09 · 223 阅读 · 0 评论 -
LeetCode--198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...原创 2018-07-12 22:15:13 · 140 阅读 · 0 评论 -
LeetCode--746. Min Cost Climbing Stairs
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of th...原创 2018-06-08 22:15:55 · 163 阅读 · 0 评论 -
LeetCode--53. Maximum Subarray
Pick OneGiven an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explan...原创 2018-05-29 22:25:02 · 191 阅读 · 0 评论 -
2018复旦大学计算机硕士招生复试上机题(3)-骨牌问题
题目描述:骨牌。 有2*n 的地板,用1*2和2*1 的骨牌进行铺地板。问共有多少种情况。 结果对 999983 取余 。 1<=n<=10000 。 样例, 输入:6输出: 13思路:1.简单dp问题,地板铺设种类,满足斐波那契数列,dp[1]=1,dp[2]=2,dp[3]=3,dp[4]=5...........2.迭代法计算dp[n]...原创 2018-05-19 21:40:46 · 2822 阅读 · 0 评论