CF44I.Toys
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her n toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still can't calm Masha down and mom is going to come home soon and punish Sasha for having made Masha crying. That's why he decides to restore the piles' arrangement. However, he doesn't remember at all the way the toys used to lie. Of course, Masha remembers it, but she can't talk yet and can only help Sasha by shouting happily when he arranges the toys in the way they used to lie. That means that Sasha will have to arrange the toys in every possible way until Masha recognizes the needed arrangement. The relative position of the piles and toys in every pile is irrelevant, that's why the two ways of arranging the toys are considered different if can be found two such toys that when arranged in the first way lie in one and the same pile and do not if arranged in the second way. Sasha is looking for the fastest way of trying all the ways because mom will come soon. With every action Sasha can take a toy from any pile and move it to any other pile (as a result a new pile may appear or the old one may disappear). Sasha wants to find the sequence of actions as a result of which all the pile arrangement variants will be tried exactly one time each. Help Sasha. As we remember, initially all the toys are located in one pile.
小玛莎喜欢把她的玩具堆在地板上。她也非常讨厌别人碰她的玩具。一天,玛莎把她全部的 n 个玩具分成了若干堆,接着她的哥哥萨沙来了,把所有堆合并成了一堆。玛莎看到后非常难过,大哭起来。萨沙至今仍无法安抚玛莎,而妈妈很快就要回家,并会因为玛莎哭泣而惩罚萨沙。因此,他决定恢复原先的堆叠方式。然而,他完全不记得玩具原先是如何堆放的。当然,玛莎还记得,但她还不会说话,只能在萨沙恰好把玩具摆成原来的样子时高兴地喊叫,以此来帮助萨沙。这意味着萨沙必须尝试所有可能的堆叠方式,直到玛莎认出正确的那种排列。由于堆与堆之间的相对位置、以及每堆内部玩具的相对位置均无关紧要,因此两种堆叠方式被视为不同,当且仅当存在两个玩具,在第一种方式中它们位于同一堆内,而在第二种方式中却不位于同一堆内。萨沙希望以最快的方式尝试所有可能的堆叠方式,因为妈妈马上就要回来了。每次操作中,萨沙可以从任意一堆中取出一个玩具,并将其放入任意另一堆中(结果可能产生新堆,也可能使原有某堆消失)。萨沙希望找到一个操作序列,使得所有可能的堆叠方式恰好被尝试一次。请帮助萨沙。如前所述,初始状态下所有玩具都在同一堆中。
输入格式
The first line contains an integer n (1 ≤ n ≤ 10) — the number of toys.
第一行包含一个整数 n(1 ≤ n ≤ 10)——玩具的数量。
输出格式
In the first line print the number of different variants of arrangement of toys into piles. Then print all the ways of arranging toys into piles in the order in which Sasha should try them (i.e. every next way must result from the previous one through the operation described in the statement). Every way should be printed in the following format. In every pile the toys should be arranged in ascending order of the numbers. Then the piles should be sorted in ascending order of the numbers of the first toys there. Output every way on a single line. Cf. the example to specify the output data format. If the solution is not unique, output any of them.
第一行输出将玩具分堆的不同方案数量。然后按萨沙应尝试的顺序输出所有将玩具分堆的方式(即:每一个后续方案必须由前一个方案通过题目描述中的操作得到)。每种方案应按如下格式输出:在每一堆中,玩具应按编号升序排列;然后各堆应按其第一个玩具的编号升序排列。每种方案单独占一行。参见样例以明确输出数据格式。若解不唯一,输出任意一种即可。
输入输出样例
输入#1
3
输出#1
5 {1,2,3} {1,2},{3} {1},{2,3} {1},{2},{3} {1,3},{2}
输入解题思路,AI测评打分。不知道怎么写?