leetcode1035
class Solution:
def maxUncrossedLines(self, A: 'List[int]', B: 'List[int]') -> int:
m = len(A)
n = len(B)
dp = [[0 for a in range(n+1)] for b in range(m+1)]
for i in range(1,m+1):
for j in range(1,n+1):
if A[i-1] == B[j-1]:
dp[i][j] = dp[i-1][j-1] + 1
else:
if dp[i][j-1] >= dp[i-1][j]:
dp[i][j] = dp[i][j-1]
else:
dp[i][j] = dp[i-1][j]
return dp[m][n]
这道题的思路是,最长公共子序列LCS,典型的DP类型题目。我最怕的类型了。
leetcode1035的更多相关文章
- [Swift]LeetCode1035.不相交的线 | Uncrossed Lines
We write the integers of A and B (in the order they are given) on two separate horizontal lines. Now ...
随机推荐
- SQLServer 关于 HAVING子句
使用HAVING子句求众数 示例表 1.使用谓词 2.使用极值函数 (思考,在条件中存在聚合函数时,不可使用where,需要使用having) 使用HAVING子句求中数
- CodeForce Div 2 C. Masha and two friends
题目链接: http://codeforces.com/contest/1080/problem/C 思路:双向延长两个矩形方块的4边,会形成一个被分割为9块的更大立方体. 计算所有的9个方框.方框中 ...
- 实体lis<T>t转换datatable
public static DataTable ListToTable<T>(List<T> list) { Type type = typeof(T) ...
- 在kerberos认证过程中Active Directory的作用
LDAP介绍 1),ladp(Lightweight Directory Access Protocol),轻量级目录访问协议,提供被称为目录服务的信息服务,特别是基于X.500(构成全球分布式的目录 ...
- 1.2.8 Excel做个滚动抽奖
1.首先要准备好数据库: 2.用RAND函数来生成随机数字,做一个辅助列: 3.制作抽奖界面: 4.输入公式: 在F3中输入下列公式并填充至F5: =INDEX(A:A,MATCH(SMALL(B:B ...
- java获取客户端ip地址工具类
public class IpUtils { private static final String[] HEADERS = { "X-Forwarded-For", " ...
- Centos 6.9 install Python3.7
# install python3sudo yum -y updatesudo yum -y install yum-utils yum install -y zlib-devel bzip2-dev ...
- iOS设置截图背景图片透明
/** 设置图片背景为透明 */- (UIImage *)imageToTransparent { // 分配内存 const int imageWidth = self.size.width; co ...
- IDEA 运行spring boot出现端口占用的问题
Description: The Tomcat connector configured to listen on port 8080 failed to start. The port may al ...
- Git世界历险记
Git-版本管理器 Git ||属于分散型版本管理系统,是为版本管理而而设计的软件.(Linux的创始人Linus Torvalds在2005年开发了Git的原型程序,在此之前人们大多选用Subve ...