Http://poj.org/problem? Id = 3661
There are two methods to reach the end point: one is to go from n-1 to N, and the other is to rest from a node to n.
DP [I] [J], I represents the minute, and J represents the current endurance.
For the first case, DP [I] [J] = DP [I-1] [J-1] + d [I];
In the second case, DP [I-1] [0] has been calculated, set the initial value of DP [I] [0] to DP [I-1] [0], that is to say, In the I-1 minute patience is 0 to continue to rest to I.
Then DP [I] [0] = max (DP [I] [0], DP [I-K] [k]);
Code:
# Include <cstdio>
Int DP [10005] [505];
Int d [10005];
Int max (int A, int B ){
If (A> B) {return ;}
Return B;
}
Int main (){
Int n, m, I, J, K;
While (~ Scanf ("% d", & N, & M )){
For (I = 1; I <= N; I ++)
Scanf ("% d", & D [I]);
DP [0] [0] = 0;
For (I = 1; I <= N; I ++ ){
For (j = 1; j <= m; j ++)
DP [I] [J] = DP [the I-1] [the J-1] + d [I];
DP [I] [0] = DP [I-1] [0];
For (k = 1; k <= M & K <= I-K; k ++)
DP [I] [0] = max (DP [I] [0], DP [I-K] [k]);
}
Printf ("% d \ n", DP [N] [0]);
}
Return 0 ;}