简体   繁体   中英

Longest Common Subsequence C (Python Script explanation)

i have been working for the last few days on a Longest Common Subsequence program, in C, using dynamic programming. Though, I have a memory issue as i am trying to process a lot of data (and i mean A LOT) which result to memory overflow.

Fortunately i have found a linear space complexity algorithm which can be useful not getting memory overflow, but is written in Python. Can someone help me understand what is going on in the picture below?

LCS距离的Python脚本

More specific i don t understand what it going on in line "curr = list(itertools.repeat(0, 1 + ny))"

For the rest i can guess.

Thanks in advance!

This is how it works:

  1. Read length of ys by the code my=len(ys) which will be 10 in the "Chimpanzee" example

  2. your itertools.repeat will be list(itertools.repeat(1,11)) will give you a list with 1 eleven times

    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

And as you said rest you have figured it out.

For more info on repeat check this out:

https://docs.python.org/2/library/itertools.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM