Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

其实考的应该就是lcs

Posted by tzkq at 2010-02-24 00:28:31 on Problem 3356 and last updated at 2010-02-24 00:30:16
我仔细想了一下, 觉得和lcs几乎一样, 只有一个地方是trick

但通过修改循环位置就可以解决

这是lcs的dp过程(pascal):
     for i:=1 to n do
     for j:=1 to m do D[i,j]:=max(D[i-1,j],D[i,j-1],D[i-1,j-1]+ord(a[i]=b[j]));


这是修正后的:
     for i:=1 to n do
     for j:=i to m do D[i,j]:=max(D[i-1,j],D[i,j-1],D[i-1,j-1]+ord(a[i]=b[j]));


其实就是更改了j的起始位置, 为避免了 a[i]=a[j](j<i)的情况, 因为这是不成立的.

譬如下面的人列举的 aac(n=3) acde(m=4)的情况

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator