Hdu3905-Sleeping of motion Gauge

Source: Internet
Author: User
Hdu3905 -- sleeping

Time Limit: 2000/1000 MS (Java/others) memory limit: 125536/65536 K (Java/Others)
Total submission (s): 1495 accepted submission (s): 565

Problem description
Zzz 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 the 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
Question:

A class has n minutes, at least m minutes of sleep, and at least l minutes of waking up each time. The value of V [I] is different every minute and can be obtained only when you are awake, find the maximum value that can be obtained. Ideas: Use DP.    DP [I] [J] indicates the maximum value that can be obtained by sleeping for J minutes within I minutes, so when I falls asleep, the value is DP [I-1] [J-1]    The US [J] array indicates J minutes of sleep. From the current I point to at least I-l minutes, it is the greatest value of waking up, that is, when I is awake, the value is us [J].

The maximum value of the two is the requested code:
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; # define maxn (A, B) (A> B? A: B) int DP [1005] [1005], DPP [1005]; int m, n, l, sum [1005], a [1005]; void fun () {int I, j; for (I = 1; I <= N; I ++) for (j = 0; j <= I & J <= m; j ++) {DP [I] [J] = DP [I-1] [J-1]; // I am asleep, so the greatest value is d [I-1] [J-1] if (I-j> = L) {DPP [J] = maxn (DPP [J] + A [I], DP [I-l] [J] + sum [I]-sum [I-l]); // This is hard to understand, I minutes To Sleep J minutes to get knowledge points are j minutes To Sleep I-1 knowledge points + A [I] And I-l minutes To Sleep J minutes + sum [I]-sum [the largest DP in I-l] [I] [J] = maxn (DPP [J], DP [I] [J]) ;}} int main () {int I; while (~ Scanf ("% d", & N, & M, & L) {memset (DP, 0, sizeof (DP); memset (DPP, 0, sizeof (DPP); for (I = 1, sum [0] = 0; I <= N; I ++) {scanf ("% d ", & A [I]); sum [I] = sum [I-1] + A [I];} fun (); printf ("% d \ n ", DP [N] [m]) ;}}

Summary: This question is still a very tangled problem. It is still the compiler. If G ++ can submit a, but it will be wa as soon as it is changed to C ++. The reason has not been found.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.