zoukankan      html  css  js  c++  java
  • leetcode1035

     1 class Solution:
     2     def maxUncrossedLines(self, A: 'List[int]', B: 'List[int]') -> int:
     3         m = len(A)
     4         n = len(B)
     5         dp = [[0 for a in range(n+1)] for b in range(m+1)]
     6         for i in range(1,m+1):
     7             for j in range(1,n+1):
     8                 if A[i-1] == B[j-1]:
     9                     dp[i][j] = dp[i-1][j-1] + 1
    10                 else:
    11                     if dp[i][j-1] >= dp[i-1][j]:
    12                         dp[i][j] = dp[i][j-1]
    13                     else:
    14                         dp[i][j] = dp[i-1][j]
    15         return dp[m][n]

    这道题的思路是,最长公共子序列LCS,典型的DP类型题目。我最怕的类型了。

  • 相关阅读:
    Uva10305(dfs)
    Uva572
    Uva122
    Uva679
    Uva136
    Uva489
    Uva133
    Uva1339
    Uva1588
    《世纪的哭泣》读后感 读书笔记
  • 原文地址:https://www.cnblogs.com/asenyang/p/10783434.html
Copyright © 2011-2022 走看看