2066: 船舱

内存限制:200 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述



大嘤帝国的东格玛水手,染染,成功竞选上了船长!

竞选上船长后,染染便看到了自己的船,一艘 nn 个船舱之间两两不通的半成品木制大船!船舱由 1,2,⋯,n1,2,,n 编号,编号为 ii 的船舱称为 ii 号船舱。

船舱之间两两不通是肯定不行的,不如说,染染希望能将所有的船舱连通。具体而言,有些一对船舱之间可以打通,打通之后这对船舱就可以直接连通。此外,一对船舱之间也可以通过若干对直接连通的船舱间接连通。形式化的,对于船舱 xx 和船舱 yy,如果存在 v1,v2,⋯,vkv1,v2,,vk 满足 v1=xv1=x 和 vk=yvk=y,且对于 i=1,2,⋯,k−1i=1,2,,k1 有船舱 vivi 和船舱 vi+1vi+1 之间直接连通,则船舱 xx 和船舱 yy 之间间接连通。只要所有 nn 个船舱两两之间直接或间接连通,就满足了染染要求的所有的船舱之间连通。

除此之外,由于船的结构问题,并不是每一对船舱之间都可以打通也就是直接连通。由于船还没有完全建好,就连哪些一对船舱之间可以打通也是不确定的。具体的情况可以通过一个 n×nn×n 的概率矩阵来表示,概率矩阵的第 ii 行第 jj 列上的元素即船舱 ii 和船舱 jj 能打通的概率,保证概率矩阵是对称矩阵且对角线全为 00

由于船的结构原因,概率矩阵中只有三种元素 0,1,p0,1,p,其中 pp 是一个还未确定的概率值。注意每对船舱之间是否能够打通的概率是相互独立的。

由于打通两个船舱有各方面的成本,染染当然希望打通的次数尽量少。形式化的,在船建成后,也就是每对船舱之间能否打通都确定后,染染希望打通船舱,使得船舱之间其恰好连接成为树状结构。在此基础上,染染会给出 qq 次询问,第 ii 次询问给出一个 pp 的可能取值 pipi,要求 p=pip=pi 时打通船舱的不同方案的数量的期望。


输入格式

The input for your prototype program will consist of one base conversion per line. 

There will be three numbers per line. The first number will be the number in the 

base you are converting from. The second number is the base you are converting from.

 The third number is the base you are converting to. There will be one or more blanks

 surrounding (on either side of) the numbers. There are several lines of input and your 

program should continue to read until the end of file is reached.

输出格式

The output will only be the converted number as it would appear on the display of the 

calculator. The number should be right justified in the 7-digit display. If the number is to large to appear on the display, 

then print ``ERROR'' (without the quotes) right justified in the display.

输入样例 复制

1111000 2 10
1111000 2 16
2102101  3 10
2102101 3   15
12312 4   2
1A   15 2
1234567 10 16
ABCD 16 15

输出样例 复制

    120
     78
   1765
    7CA
  ERROR
  11001
 12D687
   D071

分类标签