Cow Roller Coaster
Time Limit:2000MS Memory Limit:65536K
Total Submit:797 Accepted:236
Description
The cows are building a roller coaster! They want your help to design as fun a roller coaster as possible, while keeping to the budget.
The roller coaster will be built on a long linear stretch of land of length L (1 ≤ L ≤ 1,000). The roller coaster comprises a collection of some of the N (1 ≤ N ≤ 10,000) different interchangable components. Each component i has a fixed length Wi (1 ≤ Wi ≤ L). Due to varying terrain, each component i can be only built starting at location Xi (0 ≤ Xi ≤ L - Wi). The cows want to string together various roller coaster components starting at 0 and ending at L so that the end of each component (except the last) is the start of the next component.
Each component i has a "fun rating" Fi (1 ≤ Fi ≤ 1,000,000) and a cost Ci (1 ≤ Ci ≤ 1000). The total fun of the roller coster is the sum of the fun from each component used; the total cost is likewise the sum of the costs of each component used. The cows' total budget is B (1 ≤ B ≤ 1000). Help the cows determine the most fun roller coaster that they can build with their budget.
Input
Line 1: Three space-separated integers: L, N and B.
Lines 2..N+1: Line i+1 contains four space-separated integers, respectively: Xi, Wi, Fi, and Ci.
Output
Line 1: A single integer that is the maximum fun value that a roller-coaster can have while staying within the budget and meeting all the other constraints. If it is not possible to build a roller-coaster within budget, output -1.
Sample Input
5 6 10 0 2 20 6 2 3 5 6 0 1 2 1 1 1 1 3 1 2 5 4 3 2 10 2
Sample Output
17
Hint
Taking the 3rd, 5th and 6th components gives a connected roller-coaster with fun value 17 and cost 7. Taking the first two components would give a more fun roller-coaster (25) but would be over budget.
Source
USACO 2006 December Silver
在DP题中 状态的选择往往是至关重要的 要满足能完整描叙一个状态的信息 不遗漏 不多余
而有时候却发现一个状态的目标元素有两个。比如这个题目中典型的可以看出 费用和收益是一个状态的2个目标元素。而一般而言碰到这种情况 我们都会把其中一个元素放到状态中去 是一个状态的目标值确定下来做DP 其实从本质上来说 是一个枚举性质的DP 即枚举一个目标元素的所有可能值 在某个具体的值下面做DP
所以 聪明的朋友一定想到了 我们要尽可能将范围小的元素放入状态中 对
所以此题的状态设置为dp[i][j] 代表修建房子到i地址时使用费用为j的时候的最大收益值
这题的状态转移是分散的 因此最好是对于每个Component做一次转移 呵呵
讲了这么多理论 其实没什么深奥的 背包模型想大家应该都非常熟悉了 其实背包模型不是上面所说的一种特例么?只是前面所说的方法可以应用与2个甚至多个目标元素的情况

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50
