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 上推出了一款全新的电视游戏。在该游戏中,两名玩家会获得一个由 2n2n 位数字组成的数 AA。每轮开始前,双方需决定由谁进行下一步操作。每位玩家恰好进行 nn 轮操作。在第 ii 轮中,当前玩家取出 AA 的最左侧一位数字,并将其追加到自己的数字 SiS_i 的末尾;随后,该最左侧数字将从 AA 中删除。游戏初始时,两位玩家的数字 S1S_1 和 S2S_2 均为空。允许 AA、S1S_1、S2S_2 中存在前导零。游戏结束后,第一名玩家获得 S1S_1 美元,第二名玩家获得 S2S_2 美元。

某日,荷马(Homer)和玛姬(Marge)前来参与该游戏。他们事先已知数字 AA。他们希望找到一种操作序列,使得两人各自恰好进行 nn 轮操作,并使他们的总奖金(即 S1+S2S_1 + S_2)最大化。请帮助他们。

输入格式

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.

第一行包含一个整数 nn(1≤n≤181 \leq n \leq 18)。第二行包含一个整数 AA,恰好由 2n2^n 位数字组成。该数可以有前导零。

输出格式

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.

输出一行包含 2n2n 个字符「H」和「M」的字符串——表示荷马(Homer)与玛琦(Marge)的移动序列,使得他们获得的总奖金最大。每位玩家必须恰好进行 nn 次移动。若存在多种解,输出任意一种即可。

输入输出样例

  • 输入#1

    2
    1234

    输出#1

    HHMM
  • 输入#2

    2
    9911

    输出#2

    HMHM

输入解题思路,AI测评打分。不知道怎么写?

首页