CF1556F.Sports Betting
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
William is not only interested in trading but also in betting on sports matches. n teams participate in each match. Each team is characterized by strength ai . Each two teams i<j play with each other exactly once. Team i wins with probability ai+ajai and team j wins with probability ai+ajaj .
The team is called a winner if it directly or indirectly defeated all other teams. Team a defeated (directly or indirectly) team b if there is a sequence of teams c1 , c2 , ... ck such that c1=a , ck=b and team ci defeated team ci+1 for all i from 1 to k−1 . Note that it is possible that team a defeated team b and in the same time team b defeated team a .
William wants you to find the expected value of the number of winners.
输入格式
The first line contains a single integer n ( 1≤n≤14 ), which is the total number of teams participating in a match.
The second line contains n integers a1,a2,…,an ( 1≤ai≤106 ) — the strengths of teams participating in a match.
输出格式
Output a single integer — the expected value of the number of winners of the tournament modulo 109+7 .
Formally, let M=109+7 . It can be demonstrated that the answer can be presented as a irreducible fraction qp , where p and q are integers and q≡0(modM) . Output a single integer equal to p⋅q−1modM . In other words, output an integer x such that 0≤x<M and x⋅q≡p(modM) .
输入输出样例
输入#1
2 1 2
输出#1
1
输入#2
5 1 5 2 11 14
输出#2
642377629
说明/提示
To better understand in which situation several winners are possible let's examine the second test:
One possible result of the tournament is as follows ( a→b means that a defeated b ):
- 1→2
- 2→3
- 3→1
- 1→4
- 1→5
- 2→4
- 2→5
- 3→4
- 3→5
- 4→5
Or more clearly in the picture:
In this case every team from the set {1,2,3} directly or indirectly defeated everyone. I.e.:
- 1 st defeated everyone because they can get to everyone else in the following way 1→2 , 1→2→3 , 1→4 , 1→5 .
- 2 nd defeated everyone because they can get to everyone else in the following way 2→3 , 2→3→1 , 2→4 , 2→5 .
- 3 rd defeated everyone because they can get to everyone else in the following way 3→1 , 3→1→2 , 3→4 , 3→5 .
Therefore the total number of winners is 3 .