Best Cow Line
Description
FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his cows in a line and herds them past the judges.
The contest organizers adopted a new registration scheme this year: simply register the initial letter of every cow in the order they will appear (i.e., If FJ takes Bessie, Sylvia, and Dora in that order he just registers BSD). After the registration phase ends, every group is judged in increasing lexicographic order according to the string of the initials of the cows' names.
FJ is very busy this year and has to hurry back to his farm, so he wants to be judged as early as possible. He decides to rearrange his cows, who have already lined up, before registering them.
FJ marks a location for a new line of the competing cows. He then proceed

FJ需要参加年度“最佳农民”比赛,今年的比赛要求按牛名字的首字母顺序排列。为了尽早被评判,FJ决定重新排列已排队的牛。他通过不断将原队伍的第一个或最后一个牛移到新队伍尾部来完成排列。输入给出原始顺序,输出FJ能创建的最小字典序排列。
最低0.47元/天 解锁文章
848

被折叠的 条评论
为什么被折叠?



