#P16584. [GKS 2016 #C] Monster Path

    ID: 16557 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>搜索数学2016Special Judge期望Google Kick Start

[GKS 2016 #C] Monster Path

题目描述

Codejamom is a mobile game in which monster trainers walk around in the real world to catch monsters. You have an old smartphone with a short battery life, so you need to choose your path carefully to catch as many monsters as possible.

Suppose the Codejamom world is a rectangular grid with RR rows and CC columns. Rows are numbered from top to bottom, starting from 0; columns are numbered from left to right, starting from 0. You start in the cell in the RSR_Sth row and the CSC_Sth column. You will take a total of SS unit steps; each step must be to a cell sharing an edge (not just a corner) with your current cell.

Whenever you take a step into a cell in which you have not already caught a monster, you will catch the monster in that cell with probability PP if the cell has a monster attractor, or QQ otherwise. If you do catch the monster in a cell, it goes away, and you cannot catch any more monsters in that cell, even on future visits. If you do not catch the monster in a cell, you may still try to catch the monster on a future visit to that cell. The starting cell is special: you have no chance of catching a monster there before taking your first step.

If you plan your path optimally before making any move, what is the maximum possible expected number of monsters that you will be able to catch?

The battery can only support limited steps, so hurry up!

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case starts with a line of five integers: RR, CC, RSR_S, CSC_S and SS. RR and CC are the numbers of rows and columns in the grid; RSR_S and CSC_S are the numbers of the row and column of your starting position, and SS is the number of steps you are allowed to take.

The next line contains two decimals PP and QQ, where PP is the probability of meeting a monster in cells with a monster attractor, and QQ is the probability of meeting a monster in cells without a monster attractor. PP and QQ are each given to exactly four decimal places.

Each of the next RR lines contains contains CC space-separated characters; the jj-th character of the ii-th line represents the cell at row ii and column jj. Each element is either . (meaning there is no attractor in that cell) or A (meaning there is an attractor in that cell).

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the largest possible expected number of monsters that the player can catch in the given amount of steps.

yy will be considered correct if yy is within an absolute or relative error of 10610^{-6} of the correct answer.

2
4 4 0 0 5
0.8000 0.2000
. . . .
. . . .
. . A .
. A . A
10 10 9 1 4
0.6121 0.1000
. . A A . . . . . .
A . . . . . . . . .
. . A . . . . A . .
. . . A A . . . . .
. A A A . . . . . A
A . A A . . . . A .
. A . . . . . A . .
. . . . A A . . . .
. . A . . . A . . A
. . . . A . . A . .
Case #1: 1.6000000
Case #2: 1.0495336

提示

In Case #1, one of the best paths is (0,0)(0,1)(0,2)(1,2)(2,2)(2,3)(0,0)\to(0,1)\to(0,2)\to(1,2)\to(2,2)\to(2,3). On this path, the expected number of monsters that you will catch is 0.2+0.2+0.2+0.8+0.2=1.60.2 + 0.2 + 0.2 + 0.8 + 0.2 = 1.6. Remember that there is no chance of catching a monster before taking your first step, which is why there are five probabilities in the calculation, not six.

In Case #2, one of the best paths is (9,1)(9,2)(8,2)(8,3)(8,2)(9,1)\to(9,2)\to(8,2)\to(8,3)\to(8,2). On this path, the expected number of monsters that you will catch is 0.1+0.6121+0.1+0.23743359=1.049533590.1 + 0.6121 + 0.1 + 0.23743359 = 1.04953359. Since we accept results within an absolute or relative error of 10610^{-6} of the correct answer (1.049533591.04953359), 1.04953361.0495336 is accepted.

Limits

1T1001 \le T \le 100.

0RS<R0 \le R_S < R.

0CS<C0 \le C_S < C.

0Q<P10 \le Q < P \le 1.

Small dataset (Test set 1 - Visible)

1R101 \le R \le 10.

1C101 \le C \le 10.

0S50 \le S \le 5.

Large dataset (Test set 2 - Hidden)

1R201 \le R \le 20.

1C201 \le C \le 20.

0S90 \le S \le 9.