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
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