Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. ```python
  2. #==============================
  3. # l and m -> are the starting and ending indexes of the break points array respectively
  4. # i and j -> are the starting and ending indexes of the string S array respectively
  5. # q is the least cost which is returned
  6. # min finds the minimum between two integers
  7. #==============================
  8.  
  9. def BREAKING-STRING(L,l,m,i,j):
  10. n=j-i+1
  11.  
  12. if (i > j) or (l > m):
  13. return 0
  14.  
  15. if (l == m):
  16. if(L[l] <= i) and (L[l] >= j):
  17. return 0
  18.  
  19. q = 1000
  20.  
  21. for k=l to m:
  22. if (k == m):
  23. q = min(q, n+BREAKING-STRING(L,l,k-1,i,L[k])+BREAKING-STRING(L,m,m,L[k]+1,j))
  24.  
  25. elif (k==l):
  26. q = min(q, n+BREAKING-STRING(L,l,l,i,L[k])+BREAKING-STRING(L,k+1,m,L[k]+1,j))
  27.  
  28. else:
  29. q = min(q, n+BREAKING-STRING(L,l,k,i,L[k])+BREAKING-STRING(L,k+1,m,L[k]+1,j))
  30.  
  31. return q
  32. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement