CF1556F.Sports Betting
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:256MB
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.

威廉不仅对交易感兴趣,也热衷于对体育比赛下注。每场比赛有 n 支队伍参赛。每支队伍 i 由其实力值 ai 刻画。任意两支队伍 i<j 恰好进行一场比赛。其中队伍 i 获胜的概率为 ai+ajai,队伍 j 获胜的概率为 ai+ajaj。
若一支队伍能直接或间接击败所有其他队伍,则称该队伍为“胜者”。我们称队伍 a 击败(直接或间接) 队伍 b,当且仅当存在一个队伍序列 c1,c2,…,ck,满足 c1=a、ck=b,且对每个 i=1,2,…,k−1,队伍 ci 击败了队伍 ci+1。注意:可能存在队伍 a 击败队伍 b,同时队伍 b 也击败队伍 a 的情况(即存在环)。
威廉希望你计算胜者数量的期望值。
输入格式
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.
第一行包含一个整数 n(1≤n≤14),表示参加比赛的队伍总数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤106)—— 表示参加比赛的各支队伍的实力。
输出格式
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).
输出一个整数——该锦标赛获胜者人数的期望值对 109+7 取模的结果。
形式化地,令 M=109+7。可以证明答案可表示为既约分数 qp,其中 p 和 q 为整数,且 q≡0(modM)。请输出一个整数,其值等于 p⋅q−1modM。换言之,输出一个整数 x,满足 0≤x<M 且 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.:
- 1st defeated everyone because they can get to everyone else in the following way 1→2, 1→2→3, 1→4, 1→5.
- 2nd defeated everyone because they can get to everyone else in the following way 2→3, 2→3→1, 2→4, 2→5.
- 3rd 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.
为了更好地理解在哪些情况下可能存在多个获胜者,我们来分析第二个测试用例:
该锦标赛的一种可能结果如下(其中 a→b 表示 a 击败了 b):
- 1→2
- 2→3
- 3→1
- 1→4
- 1→5
- 2→4
- 2→5
- 3→4
- 3→5
- 4→5
或者更清晰地表示为下图:

在此情形下,集合 {1,2,3} 中的每支队伍均直接或间接击败了所有其他队伍。即:
- 第 1 支队伍击败了所有人,因为其可通过如下路径到达其余所有队伍:1→2、1→2→3、1→4、1→5。
- 第 2 支队伍击败了所有人,因为其可通过如下路径到达其余所有队伍:2→3、2→3→1、2→4、2→5。
- 第 3 支队伍击败了所有人,因为其可通过如下路径到达其余所有队伍:3→1、3→1→2、3→4、3→5。
因此,获胜者总数为 3。
输入解题思路,AI测评打分。不知道怎么写?