JavaScript (ES6), 69 bytes
Expects (set)(string)
.
s=>g=([c,...b],o='',[p,,q]=o)=>q?s.has(q+p):c?g(b,o)+(c>o)*g(b,c+o):0
Commented
s => // s = set of letter flagsg = ( // g is a recursive function taking: [ c, // c = next character from the landscape ...b ], // b[] = array of remaining characters o = '', // o = string of selected letters, in reverse order [ p,, // p = 1st character of o q ] = o // q = 3rd character of o) => //q ? // if q is defined: s.has(q + p) // increment the result if q + p exists in s: // else: c ? // if c is defined: g(b, o) + // do a recursive call with o unchanged (c > o) * // the 2nd call is valid only if c > o g(b, c + o) // do a recursive call with c + o : // else: 0 // stop the recursion
Python 3.8, 85 bytes
I was curious to see if a port in Python could compete with user1609012's answer.
Thanks to @tsh who managed to save 4 bytes.
f=lambda s,a,o="":o[::-2]in a or s>""==o[2:]and(s[0]>o)*f(q:=s[1:],a,s[0]+o)+f(q,a,o)