![]() ![]() #define SIZE_ARRAY(x) (sizeof(x) / sizeof(*x)) #define NUM_CODEPOINT (MAX_CODEPOINT - MIN_CODEPOINT + 1) This is very much a work in progress (as shown by the horrible messiness), but hopefully it sparks some good answers! This answer is currently broken due to a bug. Since loops over n-dimensional matrices require more logic than fixed loops, I'm using a fixed loop for the lowest dimension, and only use the generic looping logic for the remaining dimensions. Check the revision history of this post for seeing that code. But it only produced the length of the sequence, not the sequence itself. I reduced the memory usage in the initial implementation, so that it could handle n = 4 given enough time. I still predict that nobody will find a legitimate solution that goes higher than n = 4 in 2 minutes, and n = 4 looks ambitious already. Since the alphabet is moderately small here (16), that could lead to an improvement. The only thing I saw are some approaches that improve efficiency for small alphabets. So while the posted algorithm is very inefficient for larger values of n, it might actually not be possible to do massively better. Based on what I found, it looks like the problem is NP-complete. The complexity of my code is O(s ^ n), with s the length of the strings. The code implements this logic for arbitrary values of n. For 2 strings A and B, the standard recurrence looks like this: L(p, q) = 1 + L(p - 1, q - 1) if A = B The algorithm is a direct generalization of the standard dynamic programming solution to n sequences. The key is 0 in the above code, but I reserve the right to change it to an undisclosed value if I suspect anybody of (partially) hardcoding the output. The n strings of the (n-1) th test will be generated by calling rand n (and stripping the linefeeds, if requested), where rand is defined as follows: rand() In the event of a tied score of n, the submission that solved the problem for n strings in the shortest time will be declared the winner.Īll submissions will be timed on my machine (Intel Core i7-3770, 16 GiB RAM, no swap). The highest amount of strings for which your code finished in time is your score. This means that you have 120 seconds for each value of n. strings until it takes longer than 120 seconds to print a valid solution. If you require any compiler flags or a specific interpreter, please mention it in your post. ![]() Your language of choice has to have a free (as in beer) compiler/interpreter for my operating system (Fedora 21). You have to write the output, i.e., any one of the valid solutions to the LCS, to STDOUT, followed by one linefeed. The number of strings will be passed as a command-line parameter to your program. The strings are chained together with no separator and no trailing linefeed. You have two choices for the input format:Įach string (including the last) is followed by a linefeed. The input will consist of two or more strings of length 1000, consisting of ASCII characters with code points between 0x30 and 0x3F. Write a full program that solves the LCS problem, as explained above, abiding the following rules: The strings axbycz and xaybzc have 8 common subsequences of length 3: abc abz ayc ayz xbc xbz xyc xyzĪny of these would be a valid solution for the LCS problem. We've already solved this problem in the shortest amount of code. Note that T does not have to be a sub string of S i. Your task is to solve the Longest Common Subsequence problem for n strings of length 1000.Ī valid solution to the LCS problem for two or more strings S 1, … S n is any string T of maximal length such that the characters of T appear in all S i, in the same order as in T. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |