[Bzoj 1613]: [Usaco2007 jan]running Bessie's morning exercise program DP

Source: Internet
Author: User

title : http://www.lydsy.com/JudgeOnline/problem.php?id=1613
1613: [Usaco2007 jan]running Bessie's morning exercise plan
Time Limit:5 Sec Memory limit:64 MB
submit:1509 solved:731
[Submit] [Status] [Discuss]
Description

The cows plan to develop their own sports cells through exercise, and as part of that, Bessie chooses to exercise a morning run of N (1 <= n <= 10,000) minutes a day. At the beginning of every minute, Bessie chooses whether the next minute is for running or resting. Bessie's physical strength limited her distance to run. More specifically, if Bessie chooses to run within the first minute, she can run D_i (1 <= d_i <= 1,000) meters in that minute, and her fatigue will increase by 1. However, no matter when Bessie's fatigue is not more than M (1 <= m <= 500). If Bessie chooses to rest, her fatigue will be reduced by 1 per minute, but she has to rest until fatigue returns to 0. If the fatigue is 0 o'clock rest, the fatigue will not change any more. At the start of the morning run, Bessie's fatigue was 0. Also, at the end of the N-minute workout, Bessie's fatigue must return to 0 or she will not have enough energy to deal with the rest of the day. Please calculate how many meters Bessie can run.

Input

    • Line 1th: 2 integers separated by a space: N and M

    • 2nd.. N+1 Line: i+1 is 1 integers: d_i

Output

    • Line 1th: Output 1 integers, indicating the maximum distance that Bessie can run if all the constraints are met

Sample Input

5 2
5
3
4
2
10

Sample Output
9

Ideas :
Status: Dp[i][j] represents the maximum score for I-time J fatigue
The answer is dp[n][0];
Transfer: F[i][j]=f[i-1][j-1]+v[i]; each point can also reduce fatigue
F[i+j][0]=max (F[i+j][0],f[i][j]);
F[i][0]=max (F[i-1][0],f[i][0]);
O (N*M)

Code :

#include <iostream>#include <stdio.h>using namespace STD;intf[10005][505];intv[10005];intN,m;intMain () {scanf("%d%d", &n,&m); for(intI=1; i<=n;i++) {scanf("%d", &v[i]); } for(intI=1; i<=n;i++) { for(intj=1; j<=m;j++) {f[i][j]=f[i-1][j-1]+v[i];if(i+j<=n) f[i+j][0]=max (f[i+j][0],F[I][J]); } f[i][0]=max (f[i-1][0],f[i][0]); }cout<<f[n][0]<<endl;}

[Bzoj 1613]: [Usaco2007 jan]running Bessie's morning exercise program DP

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.