#P6893. [ICPC2014 WF] Buffed Buffet

[ICPC2014 WF] Buffed Buffet

题目描述

You are buying lunch at a buffet. A number of different dishes are available, and you can mix and match them to your heart’s desire. Some of the dishes, such as dumplings and roasted potatoes, consist of pieces of roughly equal size, and you can pick an integral number of such pieces (no splitting is allowed). Refer to these as “discrete dishes.” Other dishes, such as tzatziki or mashed potatoes, are fluid and you can pick an arbitrary real-valued amount of them. Refer to this second type as “continuous dishes.”

Of course, you like some of the dishes more than others, but how much you like a dish also depends on how much of it you have already eaten. For instance, even if you generally prefer dumplings to potatoes, you might prefer a potato over a dumpling if you have already eaten ten dumplings. To model this, each dish ii has an initial tastiness tit_ i, and a rate of decay of the tastiness Δti\Delta t_ i. For discrete dishes, the tastiness you experience when eating the nthn^{th} item of the dish is ti(n1)Δtit_ i - (n-1)\Delta t_ i. For continuous dishes, the tastiness you experience when eating an infinitesimal amount dxd x grams of the dish after already having eaten xx grams is (tixΔti)dx(t_ i - x \Delta t_ i) d x. In other words, the respective total amounts of tastiness you experience when eating NN items of a discrete dish or XX grams of a continuous dish are as follows:

$$\begin{aligned} \sum _{n=1}^{N} (t_ i - (n-1)\Delta t_ i) & & \text {and} & & \int _{0}^ X (t_ i - x\Delta t_ i) dx \end{aligned} $$

For simplicity, do not take into account that different dishes may or may not go well together, so define the total tastiness that you experience from a meal as the sum of the total tastinesses of the individual dishes in the meal (and the same goes for the weight of a meal – there are no food antiparticles in the buffet!).

You have spent days of painstaking research determining the numbers tit_ i and Δti\Delta t_ i for each of the dishes in the buffet. All that remains is to compute the maximum possible total tastiness that can be achieved in a meal of weight ww. Better hurry up, lunch is going to be served soon!

输入格式

The input consists of a single test case. The first line of input consists of two integers dd and ww (1d2501 \le d \le {250} and 1w100001 \le w \le {10\, 000}), where dd is the number of different dishes at the buffet and ww is the desired total weight of your meal in grams.

Then follow dd lines, the ithi^{th} of which describes the ithi^{th} dish. Each dish description is in one of the following two forms:

A description of the form “D wiw_ i tit_ i Δti\Delta t_ i” indicates that this is a discrete dish where each item weighs wiw_ i grams, with initial tastiness tit_ i and decay of tastiness Δti\Delta t_ i.

A description of the form “C tit_ i Δti\Delta t_ i” indicates that this is a continuous dish with initial tastiness tit_ i and decay of tastiness Δti\Delta t_ i.

The numbers wiw_ i, tit_ i, and Δti\Delta t_ i are integers satisfying 1wi100001 \le w_ i \le {10\, 000} and 0ti,Δti100000 \le t_ i, \Delta t_ i \le {10\, 000}.

输出格式

Display the maximum possible total tastiness of a meal of weight ww based on the available dishes. Give the answer with a relative or absolute error of at most 10610^{-6}. If it is impossible to make a meal of total weight exactly ww based on the available dishes, display impossible.

题目大意

题目描述

自助餐厅里有 nn 种食物,分为两大类,为 “离散食物”和“连续食物”。你可以通过吃食物来获得收益。

离散食物用 (w,t0,Δt)(w,t_0,\Delta t) 描述。对于这种食物,你只能吃整数个,每个重为 ww。吃的第一个收益为 t0t_0,后面每吃一个收益减少 Δt\Delta t。具体的,吃的第 ii 个这种食物 (从 11 开始标号),收益为 t0(i1)Δtt_0-(i-1)\Delta t

连续食物用 (t0,Δt)(t_0,\Delta t) 描述。对于这种食物,你可以吃任意食物的重量。如果你吃的重量为 ww,获得的收益是 t0w12Δtw2t_0w-\dfrac{1}{2}\Delta t w^2

你现在要吃重量和 恰好WW 的食物。最大化你的收益。

数据范围

n250,W10000n\le 250,W\le 10000

对于离散食物,满足 1w100001\le w\le 10000

对于所有食物,满足 0t0,t100000\le t_0,t\le 10000

输入格式

第一行是 n,Wn,W,接下来每行先来一个字母,如果是 C 表示连续食物,后面跟两个数表示 t0,Δtt_0,\Delta t;如果是 D 表示离散食物,后面跟三个数,表示 w,t0,Δtw,t_0,\Delta t

输出格式

一行一个数表示答案。相对或绝对误差不超过 1e61e-6

2 15
D 4 10 1
C 6 1

40.500000000

3 15
D 4 10 1
C 6 1
C 9 3

49.000000000

2 19
D 4 5 1
D 6 3 2

impossible

提示

Time limit: 3000 ms, Memory limit: 1048576 kB.

International Collegiate Programming Contest (ACM-ICPC) World Finals 2014