Under construction

Still being built. Things may change

Cellular Network

Time limit1sMemory limit128 MB

Summary
You sort n cells by their probabilities and split them into w ordered zones to minimize the expected number of paged cells.
Level

Medium7 of 10

Topics
Dynamic programming, Sorting, Probability
Solved
No attempts yet

Problem

A cellular network is a radio network made up of cells, each served by a base station in the cell. The base station receives call signals from the mobile users in its cell and connects those calls to the wired land-line telephone network. To route an incoming call to a mobile, the network must know which cell the mobile is currently in.

Mobiles move from cell to cell. If a mobile reported every boundary crossing, the network would always know its exact cell and paging (finding the mobile) would be trivial. In practice this is infeasible because radio bandwidth is limited, so when a call arrives the network knows only a limited set of cells the mobile might be in. Many paging strategies exist to locate a mobile efficiently; the goal is to minimize both the delay and the cost of paging until the mobile is found.

Formally, the location area is a set of nn cells C={c1,c2,…,cn}C = \{c_1, c_2, \dots, c_n\}, and the mobile is guaranteed to be in exactly one of them when a call arrives. In one paging round (one unit of time) the network can page any subset of these cells and learn whether the mobile is among the paged cells. Paging all nn cells in a single round is the fastest strategy but uses a lot of bandwidth.

The network can often estimate the mobile's whereabouts as nn independent probabilities: let pip_i be the probability that the mobile is in cell cic_i. A sequential paging strategy pages the cells one per round and stops as soon as the mobile is found. Its average cost (number of cells paged) Cˉ\bar{C} and average delay (number of rounds) Dˉ\bar{D} are:

Cˉ=∑i=1n(i×pi),Dˉ=∑i=1n(i×pi).\bar{C} = \sum_{i=1}^{n} (i \times p_i), \qquad \bar{D} = \sum_{i=1}^{n} (i \times p_i).

A parallel paging strategy pages several cells simultaneously. Sequential paging has a lower cost than parallel paging but a larger delay. Parallel paging partitions the location area into an ordered series of groups called paging zones. Let Z1,Z2,…,ZwZ_1, Z_2, \dots, Z_w be a partition of CC into ww non-empty zones. When a call arrives, all cells of Z1Z_1 are paged in the first round; if the mobile is not found, all cells of Z2Z_2 are paged in the second round, and so on. Let ni=∣Zi∣n_i = |Z_i| and let the zone probability be πi=∑cj∈Zipj\pi_i = \sum_{c_j \in Z_i} p_j. Then:

Cˉ=∑i=1w(∑j=1inj)πi,Dˉ=∑i=1w(i×πi).\bar{C} = \sum_{i=1}^{w} \left(\sum_{j=1}^{i} n_j\right) \pi_i, \qquad \bar{D} = \sum_{i=1}^{w} (i \times \pi_i).

Parallel paging trades bandwidth for time: increasing the number of zones tends to lower the cost, while decreasing it tends to raise the cost. Even for a fixed number ww of zones, the cost depends on how the cells are partitioned.

For example, take n=5n = 5 cells with these probabilities:

cic_ic1c_1c2c_2c3c_3c4c_4c5c_5
pip_i0.30.050.10.30.25

Partitioning into Z1={c1,c2,c3}Z_1 = \{c_1, c_2, c_3\} and Z2={c4,c5}Z_2 = \{c_4, c_5\} gives:

  • Cˉ=n1π1+(n1+n2)π2=3(0.3+0.05+0.1)+(3+2)(0.3+0.25)=3×0.45+5×0.55=4.1\bar{C} = n_1\pi_1 + (n_1 + n_2)\pi_2 = 3(0.3 + 0.05 + 0.1) + (3 + 2)(0.3 + 0.25) = 3 \times 0.45 + 5 \times 0.55 = 4.1
  • Dˉ=1×π1+2×π2=1(0.45)+2(0.55)=1.55\bar{D} = 1 \times \pi_1 + 2 \times \pi_2 = 1(0.45) + 2(0.55) = 1.55

Partitioning into Z1={c1,c4}Z_1 = \{c_1, c_4\} and Z2={c2,c3,c5}Z_2 = \{c_2, c_3, c_5\} gives:

  • Cˉ=n1π1+(n1+n2)π2=2(0.3+0.3)+(3+2)(0.05+0.1+0.25)=2×0.6+5×0.4=3.2\bar{C} = n_1\pi_1 + (n_1 + n_2)\pi_2 = 2(0.3 + 0.3) + (3 + 2)(0.05 + 0.1 + 0.25) = 2 \times 0.6 + 5 \times 0.4 = 3.2
  • Dˉ=1×π1+2×π2=1(0.6)+2(0.4)=1.4\bar{D} = 1 \times \pi_1 + 2 \times \pi_2 = 1(0.6) + 2(0.4) = 1.4

Given the number of cells, each cell's probability, and a fixed number ww of paging zones, partition the cells into ww zones so that the average paging cost Cˉ\bar{C} is minimized.

Input

The input begins with a line containing the number of test cases TT. Each test case consists of two lines. The first line contains two integers nn and ww: the number of cells in the location area and the number of paging zones, with 1≤w≤n≤1001 \le w \le n \le 100. The second line contains nn integers u1,u2,…,unu_1, u_2, \dots, u_n; the probability of cell cic_i is pi=ui/(u1+u2+⋯+un)p_i = u_i / (u_1 + u_2 + \dots + u_n). Every uiu_i is between 1 and 10000.

Output

For each test case, print exactly one line containing the minimum average paging cost needed to locate the mobile, rounded to exactly 4 digits after the decimal point (round half up).

Examples1

  1. Example 1

    Input
    2
    5 2
    30 5 10 30 25
    5 5
    30 5 10 30 25
    
    Expected output
    3.2000
    2.3000