Help Bob
Time limit1sMemory limit128 MB
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 (), the number of pizzas Alfredo offers. The input is terminated by a line with , which must not be processed.
Each test case then has lines. The -th line () describes pizza and begins with three integers , and : the price of the pizza (), its area (), and the number of discount coupons you receive when you buy it (). Then follow pairs of integers and : buying pizza yields a coupon for pizza (, ) giving a discount of percent (). For each the values 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 .