Language:DefaultRunning
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 5300 |
|
Accepted: 1974 |
Description The cows was trying to become better athletes, so Bessie was running on a track for exactly n (1≤ n ≤10 , minutes). During each minute, she can choose to either run or rest for the whole minute. The ultimate distance Bessie runs, though, depends on she ' exhaustion factor ', which starts at 0. When she chooses to run in minute I, she'll run exactly a distance of di (1≤ Di ≤1,000) and Her exhaustion factor would increase by 1 – but must never was allowed to exceed m (1≤ m ≤500). If she chooses to rest, her exhaustion factor would decrease by 1 for each minute she rests. She cannot commence running again until her exhaustion factor reaches 0. At the, she can choose to run or rest. At the end of the N minute Workout, Bessie ' s exaustion factor must is exactly 0, or she'll not have enough ener Gy left for the rest of the day. Find the maximal distance Bessie can run. Input * Line 1:two space-separated integers: N and M * Lines 2. N+1:line i+1 contains the single integer: Di Output * Line 1: A single integer representing the largest distance Bessie can run while satisfying the conditions. Sample Input 5 2534210
Sample Output 9
Source Usaco January Silver
|
DP[I][J] Indicates the maximum distance the fatigue of I-moment J goes
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace STD; #define N 10005int Dp[n][505],n,m,a[n];int main () {int i,j;while (~scanf ("%d%d", &n,&m)) {for (i=1;i<=n;i + +) scanf ("%d", &a[i]); Memset (Dp,0,sizeof (DP)); for (i=1;i<=n;i++) {for (j=1;j<=m;j++) dp[i][j]=dp[i-1][j-1 ]+a[i]; dp[i][0]=dp[i-1][0];for (int k=1;k<=m&&i>=k;k++) Dp[i][0]=max (Dp[i][0],dp[i-k][k]);} printf ("%d\n", Dp[n][0]);} return 0;}
POJ 3661 Running (interval dp)