DP真题

作者: SharlotteZZZ | 来源:发表于2018-10-14 06:58 被阅读0次

骨骼清奇:
LC 62
LC 337 House Robber III
LC 486 Predict the Winner
LC 312 Burst Balloons
Onsite: 考察dp的,类似与有多少条路径,从起点到终点,在一个二维grid上,leetcode有相似的题,然后如果遇到障碍或者必须经过某些位置的话咋办
[Uber] LC 91 Decode Ways
[Uber] 911 Online Election
[Uber] LC 72 Edit Distance

LC六二
A robot is located at the top-left corner of a m x n grid. The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid. How many possible unique paths are there?

著名变种:给定一个矩形的长宽,用多少种方法可以从左上角走到右上角 (每一步,只能向正右、右上 或 右下走):整个矩形遍历做DP即可,不需要想复杂。
-follow up:如果给矩形里的三个点,要求解决上述问题的同时,遍历这三个点 (切割矩形,一个一个地做DP,然后相加)
-follow up:如何判断这三个点一个是合理的,即存在遍历这三个点的路经
-follow up:如果给你一个H,要求你的路径必须向下越过H这个界。

    def uniquePaths(self, m, n):
        """
        :type m: int
        :type n: int
        :rtype: int
        """
        if not m or not n: return 0
        dp = [[1]*n for _ in range(m)]
        for i in  range(1,m):
             for j in range(1,n):
                    dp[i][j] = dp[i-1][j] + dp[i][j-1]
        return dp[-1][-1]

相关文章

  • DP真题

    骨骼清奇:LC 62LC 337 House Robber III LC 486 Predict the Win...

  • 337-打家劫舍Ⅲ-树形DP

    继打家劫舍前两题之后的第三题,普通DP->环形DP->树形DP 题目 核心思想 与前两题题意类似,都是不能偷窃相邻...

  • 920. Number of Music Playlists

    排列组合 + DP这道题即考了排列组合的知识又考了DP的知识。这道题的难点在于两处。1。 DP的定义2。DP 的递...

  • Leetcode 【39、40、77】

    问题描述:【DFS、DP】39. Combination Sum 解题思路: 这道题和 Leetcode 【DP】...

  • 131(132、1278)-分割回文串Ⅰ、Ⅱ、Ⅲ-字符串DP问题

    写在前面 这三道题可以算是一个小系列了,都是DP相关的问题。因为没怎么做过字符串DP的相关问题,在定义数组的时候真...

  • Wildcard Matching (Leetcode 44)

    个人感觉这道题的dp递归方程比regular expression那道题要容易很多。dp[i][j] 为 i-1为...

  • 2019-06-20

    DP的习惯可真费钱

  • 签到题 DP

    DP算法,经典,求解 如图所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是...

  • 3. Longest Substring Without Rep

    这是一道DP题,使用DP[i]来表示以I为结尾的子串的最大长度。转移关系式式DP[i+1]=Math.min(DP...

  • 8.24 - hard - 102

    552. Student Attendance Record II虽然知道这是一道DP题,但是这个dp状态真的很难...

网友评论

    本文标题:DP真题

    本文链接:https://www.haomeiwen.com/subject/urtzaftx.html