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. nn teams participate in each match. Each team is characterized by strength aia_i. Each two teams i<ji \lt j play with each other exactly once. Team ii wins with probability aiai+aj\frac{a_i}{a_i + a_j} and team jj wins with probability ajai+aj\frac{a_j}{a_i + a_j}.

The team is called a winner if it directly or indirectly defeated all other teams. Team aa defeated (directly or indirectly) team bb if there is a sequence of teams c1c_1, c2c_2, ... ckc_k such that c1=ac_1 = a, ck=bc_k = b and team cic_i defeated team ci+1c_{i + 1} for all ii from 11 to k−1k - 1. Note that it is possible that team aa defeated team bb and in the same time team bb defeated team aa.

William wants you to find the expected value of the number of winners.

威廉不仅对交易感兴趣,也热衷于对体育比赛下注。每场比赛有 nn 支队伍参赛。每支队伍 ii 由其实力值 aia_i 刻画。任意两支队伍 i<ji < j 恰好进行一场比赛。其中队伍 ii 获胜的概率为 aiai+aj\frac{a_i}{a_i + a_j},队伍 jj 获胜的概率为 ajai+aj\frac{a_j}{a_i + a_j}。

若一支队伍能直接或间接击败所有其他队伍,则称该队伍为“胜者”。我们称队伍 aa 击败(直接或间接) 队伍 bb,当且仅当存在一个队伍序列 c1,c2,…,ckc_1, c_2, \dots, c_k,满足 c1=ac_1 = a、ck=bc_k = b,且对每个 i=1,2,…,k−1i = 1, 2, \dots, k-1,队伍 cic_i 击败了队伍 ci+1c_{i+1}。注意:可能存在队伍 aa 击败队伍 bb,同时队伍 bb 也击败队伍 aa 的情况(即存在环)。

威廉希望你计算胜者数量的期望值。

输入格式

The first line contains a single integer nn (1≤n≤141 \leq n \leq 14), which is the total number of teams participating in a match.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1061 \leq a_i \leq 10^6) — the strengths of teams participating in a match.

第一行包含一个整数 nn(1≤n≤141 \leq n \leq 14),表示参加比赛的队伍总数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \leq a_i \leq 10^6)—— 表示参加比赛的各支队伍的实力。

输出格式

Output a single integer — the expected value of the number of winners of the tournament modulo 109+710^9 + 7.

Formally, let M=109+7M = 10^9+7. It can be demonstrated that the answer can be presented as a irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output a single integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output an integer xx such that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

输出一个整数——该锦标赛获胜者人数的期望值对 109+710^9 + 7 取模的结果。

形式化地,令 M=109+7M = 10^9+7。可以证明答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出一个整数,其值等于 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,输出一个整数 xx,满足 0≤x<M0 \le x \lt M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}。

输入输出样例

  • 输入#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→ba \rightarrow b means that aa defeated bb):

  • 1→21 \rightarrow 2
  • 2→32 \rightarrow 3
  • 3→13 \rightarrow 1
  • 1→41 \rightarrow 4
  • 1→51 \rightarrow 5
  • 2→42 \rightarrow 4
  • 2→52 \rightarrow 5
  • 3→43 \rightarrow 4
  • 3→53 \rightarrow 5
  • 4→54 \rightarrow 5

Or more clearly in the picture:

In this case every team from the set 1,2,3{ 1, 2, 3 } directly or indirectly defeated everyone. I.e.:

  • 11st defeated everyone because they can get to everyone else in the following way 1→21 \rightarrow 2, 1→2→31 \rightarrow 2 \rightarrow 3, 1→41 \rightarrow 4, 1→51 \rightarrow 5.
  • 22nd defeated everyone because they can get to everyone else in the following way 2→32 \rightarrow 3, 2→3→12 \rightarrow 3 \rightarrow 1, 2→42 \rightarrow 4, 2→52 \rightarrow 5.
  • 33rd defeated everyone because they can get to everyone else in the following way 3→13 \rightarrow 1, 3→1→23 \rightarrow 1 \rightarrow 2, 3→43 \rightarrow 4, 3→53 \rightarrow 5.

Therefore the total number of winners is 33.

为了更好地理解在哪些情况下可能存在多个获胜者,我们来分析第二个测试用例:

该锦标赛的一种可能结果如下(其中 a→ba \rightarrow b 表示 aa 击败了 bb):

  • 1→21 \rightarrow 2
  • 2→32 \rightarrow 3
  • 3→13 \rightarrow 1
  • 1→41 \rightarrow 4
  • 1→51 \rightarrow 5
  • 2→42 \rightarrow 4
  • 2→52 \rightarrow 5
  • 3→43 \rightarrow 4
  • 3→53 \rightarrow 5
  • 4→54 \rightarrow 5

或者更清晰地表示为下图:

在此情形下,集合 {1,2,3}\{ 1, 2, 3 \} 中的每支队伍均直接或间接击败了所有其他队伍。即:

  • 第 11 支队伍击败了所有人,因为其可通过如下路径到达其余所有队伍:1→21 \rightarrow 2、1→2→31 \rightarrow 2 \rightarrow 3、1→41 \rightarrow 4、1→51 \rightarrow 5。
  • 第 22 支队伍击败了所有人,因为其可通过如下路径到达其余所有队伍:2→32 \rightarrow 3、2→3→12 \rightarrow 3 \rightarrow 1、2→42 \rightarrow 4、2→52 \rightarrow 5。
  • 第 33 支队伍击败了所有人,因为其可通过如下路径到达其余所有队伍:3→13 \rightarrow 1、3→1→23 \rightarrow 1 \rightarrow 2、3→43 \rightarrow 4、3→53 \rightarrow 5。

因此,获胜者总数为 33。

输入解题思路,AI测评打分。不知道怎么写?

首页