茶香满园  
灵感源源不断
日历
<2021年2月>
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213
统计
  • 随笔 - 3
  • 文章 - 7
  • 评论 - 0
  • 引用 - 0

导航

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

相册

my friend

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 

 
Private Sub lcs(i As Integer, j As Integer, x As String, b() As Integer)

 

If i = 0 Or j = 0 Then

Exit Sub

 

ElseIf b(i, j) = 1 Then

Call lcs(i - 1, j - 1, x, b)

Text3.Text = Text3.Text + Mid(x, i, 1)

 

ElseIf b(i, j) = 2 Then

Call lcs(i - 1, j, x, b)

 

Else: Call lcs(i, j - 1, x, b)

 

End If

 

End Sub

 

Private Sub Command1_Click()

Dim x As String

Dim y As String

Dim m As Integer

Dim n As Integer

Dim i As Integer

Dim j As Integer

Dim c() As Integer

Dim b() As Integer

 

x = Text1.Text

y = Text2.Text

 

m = Len(Text1.Text)

n = Len(Text2.Text)

 

ReDim c(0 To m, 0 To n) As Integer

ReDim b(0 To m, 0 To n) As Integer

 

 

For i = 1 To m

c(i, 0) = 0

Next i

 

For i = 1 To n

c(0, i) = 0

Next i

 

For i = 1 To m

 

For j = 1 To n

 

If Mid(x, i, 1) = Mid(y, j, 1) Then

 

c(i, j) = c(i - 1, j) + 1

b(i, j) = 1

 

ElseIf (c(i - 1, j) >= c(i, j - 1)) Then

c(i, j) = c(i - 1, j)

b(i, j) = 2

 

Else: c(i, j) = c(i, j - 1)

b(i, j) = 3

 

End If

 

Next j

 

Next i

 

Call lcs(i - 1, j - 1, x, b)

 

End Sub

 

Private Sub Command2_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

End Sub
posted on 2006-06-01 11:04 小茶 阅读(391) 评论(0)  编辑 收藏 引用 所属分类: 算法
只有注册用户登录后才能发表评论。
 
Copyright © 小茶 Powered by: 博客园 模板提供:沪江博客