CF31E.TV Game
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a new TV game on BerTV. In this game two players get a number A consisting of 2_n_ digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmost digit of A and appends it to his or her number S__i. After that this leftmost digit is erased from A. Initially the numbers of both players (_S_1 and _S_2) are «empty». Leading zeroes in numbers A, _S_1, _S_2 are allowed. In the end of the game the first player gets _S_1 dollars, and the second gets _S_2 dollars.
One day Homer and Marge came to play the game. They managed to know the number A beforehand. They want to find such sequence of their moves that both of them makes exactly n moves and which maximizes their total prize. Help them.
BerTV 上推出了一款全新的电视游戏。在该游戏中,两名玩家会获得一个由 2n 位数字组成的数 A。每轮开始前,双方需决定由谁进行下一步操作。每位玩家恰好进行 n 轮操作。在第 i 轮中,当前玩家取出 A 的最左侧一位数字,并将其追加到自己的数字 Si 的末尾;随后,该最左侧数字将从 A 中删除。游戏初始时,两位玩家的数字 S1 和 S2 均为空。允许 A、S1、S2 中存在前导零。游戏结束后,第一名玩家获得 S1 美元,第二名玩家获得 S2 美元。
某日,荷马(Homer)和玛姬(Marge)前来参与该游戏。他们事先已知数字 A。他们希望找到一种操作序列,使得两人各自恰好进行 n 轮操作,并使他们的总奖金(即 S1+S2)最大化。请帮助他们。
输入格式
The first line contains integer n (1 ≤ n ≤ 18). The second line contains integer A consisting of exactly 2_n_ digits. This number can have leading zeroes.
第一行包含一个整数 n(1≤n≤18)。第二行包含一个整数 A,恰好由 2n 位数字组成。该数可以有前导零。
输出格式
Output the line of 2_n_ characters «H» and «M» — the sequence of moves of Homer and Marge, which gives them maximum possible total prize. Each player must make exactly n moves. If there are several solutions, output any of them.
输出一行包含 2n 个字符「H」和「M」的字符串——表示荷马(Homer)与玛琦(Marge)的移动序列,使得他们获得的总奖金最大。每位玩家必须恰好进行 n 次移动。若存在多种解,输出任意一种即可。
输入输出样例
输入#1
2 1234
输出#1
HHMM
输入#2
2 9911
输出#2
HMHM
输入解题思路,AI测评打分。不知道怎么写?