This page is still under construction.

Parts of this page are still being built. What you see may change.

Help Bob

Time limit1sMemory limit128 MB

Summary
Given up to 15 pizzas with prices, areas, and stacked discount coupons unlocked by buying other pizzas, find the minimum total price over total area of any nonempty purchase order.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation, Brute force
Solved
No attempts yet

Problem

Bob loves pizza but is always short on money. One day he reads that his favorite restaurant, Alfredo's Pizza Restaurant, is running a competition: they will give a large pizza to the first person who tells them the lowest achievable price per unit of area, where each pizza may be bought at most once.

"That's easy!", Bob thinks. "For each pizza I just divide its price by its area, and the smallest quotient is the answer." Unfortunately the problem is trickier. Some pizzas come with discount coupons for other pizzas, and these coupons stack — they can be combined. The pizzas must be bought one after another, and a coupon may only be used on a pizza that has not been bought yet; you cannot apply a discount retroactively to a pizza you already own.

You buy some non-empty set of pizzas (each at most once), paying the discounted price of each. The price per area of your purchase is the total price you pay divided by the total area of all pizzas you bought. Help Bob find the smallest price per area he can achieve.

Input

The input contains several test cases. Each test case starts with an integer mm (1≤m≤151 \le m \le 15), the number of pizzas Alfredo offers. The input is terminated by a line with m=0m = 0, which must not be processed.

Each test case then has mm lines. The ii-th line (1≤i≤m1 \le i \le m) describes pizza ii and begins with three integers pip_i, aia_i and nin_i: the price of the pizza (1≤pi≤100001 \le p_i \le 10000), its area (1≤ai≤100001 \le a_i \le 10000), and the number of discount coupons you receive when you buy it (0≤ni<m0 \le n_i < m). Then follow nin_i pairs of integers xi,jx_{i,j} and yi,jy_{i,j}: buying pizza ii yields a coupon for pizza xi,jx_{i,j} (1≤xi,j≤m1 \le x_{i,j} \le m, xi,j≠ix_{i,j} \ne i) giving a discount of yi,jy_{i,j} percent (1≤yi,j≤501 \le y_{i,j} \le 50). For each ii the values xi,jx_{i,j} are pairwise distinct.

Output

For each test case, print one line with the lowest achievable price per area: the minimum, over every non-empty set of purchased pizzas and every purchase order, of (total price paid) / (total area bought). Round this value to exactly 4 digits after the decimal point.

Coupons combine multiplicatively. For example, a pizza with base price 10 that receives a 50 percent and a 20 percent coupon before it is bought costs 10×0.5×0.8=410 \times 0.5 \times 0.8 = 4.

Examples2

  1. Example 1

    Input
    1
    80 30 0
    2
    200 100 1 2 50
    200 100 0
    5
    100 100 2 3 50 2 50
    100 100 1 4 50
    100 100 1 2 40
    600 600 1 5 10
    1000 10 1 1 50
    0
    
    Expected output
    2.6667
    1.5000
    0.5333
    
  2. Example 2

    Input
    1
    7 3 0
    0
    
    Expected output
    2.3333