#FW0000091. Vé xe có giá ngẫu nhiên (Randomly-priced Tickets)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Vé xe có giá ngẫu nhiên (Randomly-priced Tickets)
Randomly-priced Tickets
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are towns with directed coach connections. The fare for each ride is independently uniform over integers . For each source, destination, and budget , calculate the probability that the sum of fares of a route with the fewest rides does not exceed . An unreachable destination has probability zero; travelling from a town to itself needs no ticket.
Input
First , then directed-adjacency Y/N strings of length , then queries s t B with 1-based towns and a nonnegative budget.
Output
Print one probability between 0 and 1 with exactly six digits after the decimal point per query.
Subtasks
-
Subtask 1 (40 points): $2\le n\le7,\ 1\le R\le8,\ 1\le q\le10,\ 0\le B\le250$. ; chuỗi dài chỉ có
Y/N; các lượt xe có giá độc lập, đều trong . -
Subtask 2 (60 points): $2\le n\le26,\ 1\le R\le25,\ 1\le q\le10,\ 0\le B\le250$. ; chuỗi dài chỉ có
Y/N; các lượt xe có giá độc lập, đều trong .
Examples
Input
3 4
NYY
YNY
YYN
2
1 3 1
1 3 4
Output
0.250000
1.000000
Explanation
Town 1 directly reaches town 3 in one ride. The ticket price is uniform over 1,2,3,4, so budget 1 succeeds with probability 0.25 and budget 4 with probability 1.