Longest Common Subsequence of Two Strings containing a particular Substring
APL (45)

⌈/0,⍴¨m/⍨∨/¨⍞∘⍷¨m←⊃∩/{/∘⍵¨↓⍉(z/2)⊤⍳2*z←⍴⍵}¨⍞⍞


Explanation:


¨⍞⍞: read two lines. For each of them:

⍳2*z←⍴⍵: get the numbers from 1 up to 2^length. 
(z/2)⊤: encode each number as bits
↓⍉: separate each string of bits into its own array
/∘⍵¨: and use each of them as a bitmask on the string, giving the subsequences

m←⊃∩/: take the intersection of the two arrays of subsequences, store in m
∨/¨⍞∘⍷¨: read a third line, and see in which subsequences it occurs
m/⍨: select those elements from m that contained the third line
⍴¨: get the length of each remaining subsequence
0,: add a zero entry in case the resulting list is empty
⌈/: get the highest number in the list


Test cases:

      ⌈/0,⍴¨m/⍨∨/¨⍞∘⍷¨m←⊃∩/{/∘⍵¨↓⍉(z/2)⊤⍳2*z←⍴⍵}¨⍞⍞
ABCDEF
CDEFAB
B
 2 
      ⌈/0,⍴¨m/⍨∨/¨⍞∘⍷¨m←⊃∩/{/∘⍵¨↓⍉(z/2)⊤⍳2*z←⍴⍵}¨⍞⍞
HELLO
WORLD
SUCKS
 0
      ⌈/0,⍴¨m/⍨∨/¨⍞∘⍷¨m←⊃∩/{/∘⍵¨↓⍉(z/2)⊤⍳2*z←⍴⍵}¨⍞⍞
ABCXD
BCDEF
CD
 3 
      ⌈/0,⍴¨m/⍨∨/¨⍞∘⍷¨m←⊃∩/{/∘⍵¨↓⍉(z/2)⊤⍳2*z←⍴⍵}¨⍞⍞
X
Y
Z
 0