CF1556F.Sports Betting

普及/提高-

通过率:0%

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 < 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 k1k - 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.

输入格式

The first line contains a single integer nn ( 1n141 \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 ( 1ai1061 \leq a_i \leq 10^6 ) — 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+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 pq1modMp \cdot q^{-1} \bmod M . In other words, output an integer xx such that 0x<M0 \le x < M and xqp(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 ( aba \rightarrow b means that aa defeated bb ):

  • 121 \rightarrow 2
  • 232 \rightarrow 3
  • 313 \rightarrow 1
  • 141 \rightarrow 4
  • 151 \rightarrow 5
  • 242 \rightarrow 4
  • 252 \rightarrow 5
  • 343 \rightarrow 4
  • 353 \rightarrow 5
  • 454 \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.:

  • 11 st defeated everyone because they can get to everyone else in the following way 121 \rightarrow 2 , 1231 \rightarrow 2 \rightarrow 3 , 141 \rightarrow 4 , 151 \rightarrow 5 .
  • 22 nd defeated everyone because they can get to everyone else in the following way 232 \rightarrow 3 , 2312 \rightarrow 3 \rightarrow 1 , 242 \rightarrow 4 , 252 \rightarrow 5 .
  • 33 rd defeated everyone because they can get to everyone else in the following way 313 \rightarrow 1 , 3123 \rightarrow 1 \rightarrow 2 , 343 \rightarrow 4 , 353 \rightarrow 5 .

Therefore the total number of winners is 33 .

首页