Topic Portal
1 /*2 Test Instructions: Select K-m long intervals, making the sum maximum3 01 Backpack: Dp[i][j] Indicates that the interval of [I-m+1, I] is selected or not selected at the position of I, when it is the first J interval. 4 01 Knapsack thought, State transfer equation: dp[i][j] = max (Dp[i-1][j], dp[i-m][j-1] + sum[i]-sum[i-m]);5 in two for loops, each time the value of Dp[i][j] is updated6 */7#include <cstdio>8#include <cstring>9#include <algorithm>Ten#include <cmath> One using namespacestd; A -typedefLong Longll; - Const intMAXN = 5e3 +Ten; the Const intINF =0x3f3f3f3f; - ll A[MAXN]; - ll SUM[MAXN]; - ll DP[MAXN][MAXN]; + - intMainvoid)//codeforces Round #267 (Div. 2) C. George and Job + { A intN, M, K; at while(SCANF ("%d%d%d", &n, &m, &k) = =3) - { -memset (SUM,0,sizeof(sum)); - for(intI=1; i<=n; ++i) {scanf ("%i64d", &a[i]); Sum[i] = sum[i-1] +a[i];} - -ll ans =0; in for(intI=m; i<=n; ++i) - { toll tmp = Sum[i]-sum[i-m]; + for(intj=1; j<=k; ++j) - { theDP[I][J] = max (dp[i-1][J], dp[i-m][j-1] +tmp); * } $Ans =Max (ans, dp[i][k]);Panax Notoginseng } - theprintf ("%i64d\n", ans); + } A the + return 0; - } $ $ /* - 5 2 1 - 1 2 3) 4 5 the 7 1 3 - 2 7 5 0Wuyi */
01 Backpack codeforces Round #267 (Div. 2) C. George and Job