The main idea here is that since every string is split into exactly 2 parts, it follows that if lMax is the length of the longest fragment, and lMin is the length of the shortest fragment, then a string of length lMax would obviously be paired with a string of length lMin, in the original string. To generalize, a fragment of length l[K] would be paired with one of length l[M], such that l[K] + l[M] = lMax + lMin = length of the original string.
What we need to determine is this pairing, and the order in which these string pairs need to be concatenated.
This can be done as follows :
1.Sort all the strings by length. Let the length of all the strings be l[1]...l[K] in sorted order
2.Pair all strings of length l[1], with those of length l[K], in all possible orders ( i.e., The string of length l[1] first, followed by the one of length l[K], and the reverse order ). At most, 8 such distinct strings may be formed, as there may be atmost 2 distinct strings of any given length. Add these to a set to prevent repetition of duplicates.
3.Now, similarly find all strings that can be formed by pairing a string of length l[2], with some string of length l[K-1]. Find the intersection of this set, with the set formed in step 2. Let us call this intersection set "Result"
4.Repeat the above procedure with all strings of length l[i] and l[K+1-i], for all valid values for i. For each such value of i, take the intersection of the set of possible strings that may be formed, with the "Result" set obtained previously, and call this intersection the new "Result" set
5.Continue the above process till the "Result" set contains just one string. This is the final answer, i.e, the original string.
6.If all i values have been tried, and the "Result" set contains more than one string, output any of its elements, as in such a case, there is no unique answer.
ความคิดหลักว่า ทุกสายจะแบ่งออกเป็น 2 อย่างส่วน ดังนั้นที่ถ้า lMax คือ ความยาวของส่วนที่ยาวที่สุด และ lMin ความยาวของส่วนที่สั้นที่สุด แล้วเป็นสายอักขระความยาว lMax จะเห็นได้ชัดว่าถูกจับคู่กับสายความยาว lMin ในต้นฉบับ การทั่วไป ส่วนของความยาว l [K] จะถูกจับคู่กับหนึ่งความยาว l [M], เช่นที่ l [K] + l [M] = lMax + lMin =ความยาวของต้นฉบับสิ่งที่เราต้องการตรวจสอบเป็นการจับคู่นี้ และใบที่คู่สายเหล่านี้จำเป็นต้องมีการเชื่อมรวมนี้สามารถทำได้ดังนี้:1.เรียงลำดับสายอักขระทั้งหมดตามความยาว ให้ความยาวของสายอักขระมี l [1]... [K] l ในลำดับการเรียงลำดับ2.จับคู่สายอักขระทั้งหมดของ l ความยาว [1], l ความยาว [K], เหล่านั้นในใบสั่งได้ทั้งหมด (เช่น สายอักขระความยาว l [1] ก่อน ตาม ด้วยหนึ่งยาว l [K], และใบสั่งย้อนหลัง) สูงสุด สายที่แตกต่างกันเช่น 8 อาจเกิด ว่าจะมี atmost ใน 2 แตกสายความยาวใด ๆ กำหนดขึ้น เพิ่มการตั้งค่าเพื่อป้องกันการซ้ำซ้ำเหล่านี้3.Now ค้นหาในทำนองเดียวกันทั้งหมดสายที่สามารถเกิดขึ้น โดยการจับคู่สายอักขระความยาว l [2], กับบางสายอักขระความยาว l [K-1] หาจุดตัดของชุดนี้ มีการตั้งค่าที่เกิดขึ้นในขั้นตอน 2 เราเรียกชุดนี้แยก "ผล"4.ทำซ้ำขั้นตอนข้างต้น ด้วยสายอักขระทั้งหมดของ l ความยาว [i] l [K + 1-i], สำหรับทุกค่าที่ถูกต้องสำหรับฉัน สำหรับแต่ละดังกล่าวค่าของฉัน ใช้ของชุดของสายอักขระที่เป็นไปได้ที่อาจเกิด ขึ้น มีการตั้งค่า "ผล" ที่ได้รับก่อนหน้านี้ และเรียกสี่แยกนี้ "ผล" ชุดใหม่5.ทำกระบวนการข้างต้นจนถึงชุด "ผลลัพธ์" ประกอบด้วยสายอักขระเดียว นี่คือคำตอบสุดท้าย เช่น ต้นฉบับ6.ถ้าทั้งหมดฉันพยายามค่า และการตั้งค่า "ผล" ประกอบด้วยมากกว่าหนึ่งสาย ผลลัพธ์ใด ๆ ขององค์ประกอบ ในกรณี มีคำตอบเฉพาะไม่
การแปล กรุณารอสักครู่..
