#abc313f. F - Flip Machines

F - Flip Machines

Score : 625625 points

问题描述

设有 NN 张卡片,编号为 11NN。每张卡片的一面都写有一个整数;第 ii 张卡片正面写有整数 AiA_i,背面写有整数 BiB_i。最初,所有卡片都是正面朝上。

共有 MM 台机器,编号从 11MM。第 jj 台机器上有两个(不一定互异)整数 XjX_jYjY_j,它们都在 11NN 的范围内。如果启动第 jj 台机器,它将以 12\frac{1}{2} 的概率翻转卡片 XjX_j,并以剩下的 12\frac{1}{2} 的概率翻转卡片 YjY_j。每次启动机器时,这个概率都是独立的。

Snuke 将执行以下操作:

  1. 选择一个包含从 11MM 整数的集合 SS
  2. 按升序遍历集合 SS 中的每个元素,并依次启动对应编号的机器。

在 Snuke 对 SS 的所有可能选择中,找出该过程结束后,卡片正面朝上的整数之和的最大期望值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN cards numbered 11 through NN. Each face of a card has an integer written on it; card ii has AiA_i on its front and BiB_i on its back. Initially, all cards are face up.

There are MM machines numbered 11 through MM. Machine jj has two (not necessarily distinct) integers XjX_j and YjY_j between 11 and NN. If you power up machine jj, it flips card XjX_j with the probability of 12\frac{1}{2}, and flips card YjY_j with the remaining probability of 12\frac{1}{2}. This probability is independent for each power-up.

Snuke will perform the following procedure.

  1. Choose a set SS consisting of integers from 11 through MM.
  2. For each element in SS in ascending order, power up the machine with that number.

Among Snuke's possible choices of SS, find the maximum expected value of the sum of the integers written on the face-up sides of the cards after the procedure.

Constraints

  • 1N401\leq N \leq 40
  • 1M1051\leq M \leq 10^5
  • 1Ai,Bi1041\leq A_i,B_i \leq 10^4
  • 1Xj,YjN1\leq X_j,Y_j \leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

ANA_N BNB_N

X1X_1 Y1Y_1

\vdots

XMX_M YMY_M

Output

Print the answer. Your output is considered correct if the absolute or relative difference from the true value is at most 10610^{-6}.

Sample Input 1

3 1
3 10
10 6
5 2
1 2

Sample Output 1

19.500000

If SS is chosen to be an empty set, no machine is powered up, so the expected sum of the integers written on the face-up sides of the cards after the procedure is 3+10+5=183+10+5=18.

If SS is chosen to be {1}\lbrace 1 \rbrace, machine 11 is powered up.

  • If card X1=1X_1 = 1 is flipped, the expected sum of the integers written on the face-up sides of the cards after the procedure is 10+10+5=2510+10+5=25.
  • If card Y1=2Y_1 = 2 is flipped, the expected sum of the integers written on the face-up sides of the cards after the procedure is 3+6+5=143+6+5=14.

Thus, the expected value is 25+142=19.5\frac{25+14}{2} = 19.5.

Therefore, the maximum expected value of the sum of the integers written on the face-up sides of the cards after the procedure is 19.519.5.

Sample Input 2

1 3
5 100
1 1
1 1
1 1

Sample Output 2

100.000000

Different machines may have the same (Xj,Yj)(X_j,Y_j).

Sample Input 3

8 10
6918 9211
16 1868
3857 8537
3340 8506
6263 7940
1449 4593
5902 1932
310 6991
4 4
8 6
3 5
1 1
4 2
5 6
7 5
3 3
1 5
3 1

Sample Output 3

45945.000000

update @ 2024/3/10 08:56:27