CF424E.Colored Jenga

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Cold winter evenings in Tomsk are very boring — nobody wants be on the streets at such a time. Residents of Tomsk while away the time sitting in warm apartments, inventing a lot of different games. One of such games is 'Colored Jenga'.

This game requires wooden blocks of three colors: red, green and blue. A tower of n levels is made from them. Each level consists of three wooden blocks. The blocks in each level can be of arbitrary colors, but they are always located close and parallel to each other. An example of such a tower is shown in the figure.

The game is played by exactly one person. Every minute a player throws a special dice which has six sides. Two sides of the dice are green, two are blue, one is red and one is black. The dice shows each side equiprobably.

If the dice shows red, green or blue, the player must take any block of this color out of the tower at this minute so that the tower doesn't fall. If this is not possible, the player waits until the end of the minute, without touching the tower. He also has to wait until the end of the minute without touching the tower if the dice shows the black side. It is not allowed to take blocks from the top level of the tower (whether it is completed or not).

Once a player got a block out, he must put it on the top of the tower so as to form a new level or finish the upper level consisting of previously placed blocks. The newly constructed levels should have all the same properties as the initial levels. If the upper level is not completed, starting the new level is prohibited.

For the tower not to fall, in each of the levels except for the top, there should be at least one block. Moreover, if at some of these levels there is exactly one block left and this block is not the middle block, the tower falls.

The game ends at the moment when there is no block in the tower that you can take out so that the tower doesn't fall.

Here is a wonderful game invented by the residents of the city of Tomsk. I wonder for how many minutes can the game last if the player acts optimally well? If a player acts optimally well, then at any moment he tries to choose the block he takes out so as to minimize the expected number of the game duration.

Your task is to write a program that determines the expected number of the desired amount of minutes.

汤姆斯克寒冷的冬夜十分无聊——此时没人愿意走上街头。汤姆斯克的居民们则待在温暖的公寓里,发明出各种各样的游戏来消磨时光。其中一种游戏叫做“彩色积木塔(Colored Jenga)”。

该游戏需要三种颜色的木块:红色、绿色和蓝色。用这些木块搭建一座共 nn 层的塔。每层均由三块木块组成。每层中的木块可为任意颜色,但始终彼此紧邻且相互平行。这样的塔的一个示例如下图所示:

该游戏仅由一名玩家进行。每分钟,玩家掷一枚特殊的六面骰子。该骰子有六个面:其中两个面为绿色,两个面为蓝色,一个面为红色,一个面为黑色。每个面出现的概率均等。

  • 若骰子显示红色、绿色或蓝色,则玩家必须在该分钟内从塔中取出一块对应颜色的木块,且保证塔不倒塌;
  • 若无法完成上述操作(即不存在满足条件的该色木块),则玩家须等待至该分钟结束,且不得触碰塔;
  • 若骰子显示黑色,则玩家同样须等待至该分钟结束,且不得触碰塔。

禁止从塔的最顶层(无论其是否已完整)取走任何木块。

一旦玩家成功取出一块木块,他必须将该木块置于塔顶,用以构建新的一层,或补全当前尚未完成的顶层(该顶层由之前已放置的木块构成)。所有新构建的层必须具备与初始各层完全相同的性质。若当前顶层尚未完成,则不允许开始构建新层。

为确保塔不倒塌,需满足以下条件:

  • 除最顶层外,其余每一层中至少须保留一块木块;
  • 此外,若某一层(非顶层)中恰好仅剩一块木块,且该木块不是中间位置的木块,则塔将倒塌。

当塔中不存在任何一块木块,使得取出它之后塔仍不倒塌时,游戏结束。

这是汤姆斯克市民所发明的一款精彩游戏。我很好奇:若玩家采取最优策略,游戏最多可持续多少分钟?所谓“最优策略”,是指玩家在每一时刻均选择取出某一块木块,以使得游戏期望持续时间最小化。

你的任务是编写一个程序,计算该期望持续时间(单位:分钟)。

输入格式

The first line of the input contains the only integer n (2 ≤ n ≤ 6) — the number of levels in the tower.

Then n lines follow, describing the levels of the tower from the bottom to the top (the first line is the top of the tower). Each level is described by three characters, the first and the third of them set the border blocks of the level and the second one is the middle block. The character that describes the block has one of the following values 'R' (a red block), 'G' (a green block) and 'B' (a blue block).

输入的第一行包含唯一一个整数 nn(2≤n≤62 \leq n \leq 6)—— 表示塔的层数。

接下来是 nn 行,描述塔的各层,从底部到顶部(第一行为塔顶)。每一层由三个字符描述:第一个和第三个字符表示该层的左右边界方块,第二个字符表示中间方块。用于描述方块的字符取值为以下之一:'R'(红色方块)、'G'(绿色方块)、'B'(蓝色方块)。

输出格式

In the only line of the output print the sought mathematical expectation value. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

在输出的唯一一行中打印所求的数学期望值。若答案的相对误差或绝对误差不超过 10−610^{-6},则视为正确。

输入输出样例

  • 输入#1

    6
    RGB
    GRG
    BBB
    GGR
    BRG
    BRB

    输出#1

    17.119213696601992

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

首页