Codeforces Beta Round 31(Div. 2,Codeforces 格式)
E
电视游戏
TV Game
Codeforces
2400
原题
← D→

电视游戏AI (CI翻译)

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.

BerTV 上推出了一款新的电视游戏。在这个游戏中,两名玩家会得到一个由 $2*n*$ 位数字组成的数字 $*A*$。在每一回合开始前,玩家们决定由谁进行下一步操作。每位玩家都必须恰好进行 $*n*$ 次操作。在第 $*i*$ 位玩家的回合中,他或她会取出 $*A*$ 最左侧的数字,并将其添加到自己的数字 $*S*_{*i*}$ 末尾。之后,这个最左侧的数字会从 $*A*$ 中删除。开始时,两位玩家的数字($*S*_{*1}$ 和 $*S*_{*2}$)都是“空”的。数字 $*A*$、$*S*_{*1}$ 和 $*S*_{*2}$ 均允许有前导零。游戏结束时,第一位玩家获得 $*S*_{*1}$ 美元,第二位玩家获得 $*S*_{*2}$ 美元。AI (CI翻译)

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.

一天,Homer 和 Marge 来参加这个游戏。他们事先得知了数字 $*A*$。他们希望找到一种操作序列,使两人都恰好进行 $*n*$ 次操作,并使他们获得的总奖金最大。请帮助他们。AI (CI翻译)

Input

输入格式

AI (CI翻译)

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$)。第二行包含一个恰好由 $2*n*$ 位数字组成的整数 $*A*$。这个数字可能有前导零。AI (CI翻译)

Output

输出格式

AI (CI翻译)

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.

输出一行由 $2*n*$ 个字符 «H» 和 «M» 组成的字符串,表示能使他们获得的总奖金最大的一系列操作。每位玩家都必须恰好进行 $*n*$ 次操作。如果有多种方案,输出任意一种即可。AI (CI翻译)

样例

Input #1
2
1234
Output #1
HHMM
InputCopy OutputCopy
Input #2
2
9911
Output #2
HMHM
InputCopy OutputCopy
题目信息
题号
31E
时间限制
2 s
内存限制
256 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。