Sleeping
Time Limit: 2000/1000 MS (Java/others) memory limit: 125536/65536 K (Java/Others)
Total submission (s): 1514 accepted submission (s): 578
Problem descriptionzzz is an enthusiastic acmer and he has Ds lots of time on training. he always stays up late for training. he needs enough time to sleep, and hates skipping classes. so he always sleeps in the class. with the final exams coming, he
Has to spare some time to listen to the teacher. today, he hears that the teacher will have a revision class. the class is n (1 <=n <= 1000) minutes long. if ZZZ listens to the teacher in the I-th minute, he can get ai points (1 <= AI <= 1000 ). if he starts listening,
He will listen to the teacher at least l (1 <= L <= N) minutes consecutively. it's the most important that he must have at least m (1 <= m <= N) minutes for sleeping (the M minutes needn't be consecutive ). suppose ZZZ knows the points he can get in every minute.
Now help ZZZ to compute the Maximal Points he can get.
Inputthe input contains several cases. the first line of each case contains three integers n, m, l mentioned in the description. the second line follows n integers separated by spaces. the I-th integer AI means there are ai points in
I-th minute.
Outputfor each test case, output an integer, indicating the Maximal Points ZZZ can get.
Sample Input
10 3 31 2 3 4 5 6 7 8 9 10
Sample output
49
Source2011 multi-university training contest 7-host by ECNU
Recommendxubiao
A class has n minutes, at least m minutes of sleep, and at least l minutes of waking up each time. Different values can be obtained only when you are awake, find the maximum value that can be obtained.
Ideas:
Because V [I]> 0, you can only sleep for M minutes to get the maximum value.
Use DP.
DP [I] [J] indicates the maximum value that can be obtained by sleeping for J minutes at the I minute. Note: The DP [I] [J] meets the question requirements at each point.
In the up [J] array, sleeping for J minutes starts from the current I point to at least I-l minutes.
When point I falls asleep, the value is DP [I-1] [J-1]
Value of up when I is awake [J]
Calculate the maximum value of the two
# Include <iostream> # include <string. h> # include <stdio. h> using namespace STD; int DP [1010] [1010], up [1010]; int s [1010]; int n, l, m; int Ma (int, int B) {return A> B? A: B;} int main () {int I, j, A; while (~ Scanf ("% d", & N, & M, & L) {s [0] = 0; for (I = 1; I <= N; I ++) {scanf ("% d", & S [I]); s [I] + = s [I-1];} memset (DP, 0, sizeof DP); memset (up, 0, sizeof up); for (I = 1; I <= N; I ++) {A = s [I]-s [I-1]; // obtain the I-minute score for (j = 0; j <= I & J <= m; j ++) {// do not worry that the J-1 is a negative value. The default DP [0] [-1] is 0. DP [I] [J] = DP [I-1] [J-1]; // The value of the I-minute sleep. Next, consider the maximum value of I-minute learning if (I-L> = J) // ensure that there are at least l minutes of lectures before I. Otherwise, you will not be able to attend lectures in the I minute {up [J] = MA (up [J] +, DP [I-l] [J] + s [I]-s [I-l]); // up [J] indicates the maximum value of attending L-1 minutes before I [I] [J] = MA (DP [I] [J], up [J]); // DP [I-l] [J] + sum [I]-sum [I-l] so that at least I-l to l can be awake.} // The Value of up [J] is always the maximum value for listening within at least 1-1 minutes before I.} printf ("% d \ n ", DP [N] [m]);} return 0 ;}