HBC223540[NOIP2002]矩形覆盖,深度优先搜索(DFS),NOIP复赛,搜索MedianInversionString题解

爱的那么颓废 算法基础篇 36 0
不断提升技能,才能在职场中立于不败之地!全网最全C++题库,助您成为编程领域的佼佼者。
This problem uses two concepts:medianandinversion. Median: Assume we have a sorted list of elements e1, e2, e3, … We define median as the element in the middle of the list (i.e., halfwa

This problem uses two concepts: median and inversion. Median : Assume we have a sorted list of elements e1, e2, e3, … We define median as the element in the middle of the list (i.e., halfway through the list). If there are an odd number of elements in the list, there is only one median element, e.g., if the list has 13 elements, then e7 is the median element (there are as many elements in the list before e7 as there are after e7). If there are an even number of elements in the list, there are two median elements, e.g., if the list has 14 elements, then e7 and e8 are the median elements (there are as many elements in the list before e7 as there are after e8). Inversion : Assume we have a string containing only the letters ‘A’ and ‘B’, e.g., AAABABAA. We define an inversion to be a pair of letters in the string where one letter is B, the other letter is A, and the position of B in the string is earlier than the position of A in the string. For our sample string, the B at position 4 and the A at position 5 form an inversion. Similarly, the B at position 4 and the A at position 7 form an inversion. There is a total of five inversions in the sample string Your friend, Michio, has a list of strings, each string containing only the letters ‘A’ and ‘B’. Each string has n letters. Each string Michio has contains exactly k inversions. Michio claims that he has all strings of exactly k inversions. You want to test his theory.  Michio has sorted the strings in lexicographical order, and you will give the median string(s) to check if he has the correct strings.  Given the length (number of letters) in each string and the desired number of inversions, output the median string(s) in the list of strings with the given length.

HBC223540[NOIP2002]矩形覆盖,深度优先搜索(DFS),NOIP复赛,搜索MedianInversionString题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。

标签: HBC223540[NOIP2002]矩形覆盖 深度优先搜索(DFS) NOIP复赛 搜索MedianInversionString题解