TADM2E 8.13

From Algorithm Wiki
Revision as of 20:18, 25 April 2020 by Eng.mrgh (talk | contribs) (lm variable added. Code style changed from python2 to python3. And the float("inf") , the infinity in python replaced with a large number.)
Jump to: navigation, search

a=raw_input() # the input string m=raw_input().split(" ") # the set of tokens separated by space n=len(m) k=int(raw_input()) # the maximum length of the token l=[float("inf")]*(len(a)+1) l[0]=0 for i in range(1,len(a)+1):

   lm = 0
   while(lm<I):
       cost = float("inf")
       if a[lm:i] in m:
           cost=l[lm]+1
       if cost < l[i] :
           l[i] = cost
       lm=lm+1

print(l[-1])


Python Based implementation