轻量级前端框架助力开发者提升项目效率与性能
767
2022-10-03
UPC 1053 Mysterious Treasure (记忆化搜索)
Description
WNJXYK and DIDIDI is playing a game. DIDIDI draws a directed graph G on the paper which contains n points, m directed edges and no cycle. WNJXYK starts from point 1. For every round, WNJXYK will randomly select one of the directed edges which start from current point with equal possibility, and go to next point by this edge. And the game will continue until such edge doesn’t exist. DIDIDI will place the treasure on point n, if WNJXYK go through this point, he can get the treasure. WNJXYK have one chance to delete one edge(he can also don’t choose to delete), that he can increase the probability of getting a treasure. Your assignment is to calculate the probability of WNJXYK getting the treasure in the optimal condition.
Input
The first line of input contains a positive integer T telling you there are T test cases followed.For each test case, the first line contains two integers n , m, indicating the number of points ,the number of edges.Then the following are m lines, each of which contains two integers x and y, indicating there is a edge from x to y.It is guaranteed that there does not exist multiple edge.
Output
For each test case, print a line “Case #x: y”, where x is the case number (starting from 1) and y is the probability of he getting the treasure. (round to six decimal places).
Sample Input
24 41 21 31 42 34 51 21 31 42 32 4
Sample Output
Case #1: 0.500000Case #2: 0.750000
题意
一个有向图,我们可以从中至多删除一条边,求从 1 到 n 的概率最大是多少。
思路
反向建图,枚举删除每一条边。
图中不存在环,因此到达每一个点的值都是由其父节点等概率分配来的,于是我们可以统计每个点有多少个孩子,然后进行记忆化搜索。
时间复杂度: O(T×m×n)
AC 代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~