1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream> #include <cstring> #include <string> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cmath> #include <set> #include <map>
#define INF 0x7f7f7f7f #define MAXN 100005 #define N 200005 #define P 2 #define MOD 99991
typedef long long ll;
namespace fastIO { inline int () { char c = getchar(); int x = 0, f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } }
using namespace fastIO; using namespace std;
namespace segment_Tree { struct Tree { int l, r, max; } tree[4 * MAXN];
inline void push_up(int x) { tree[x].max = max(tree[x << 1].max, tree[x << 1 | 1].max); }
inline void build(int x, int l, int r) { tree[x].l = l, tree[x].r = r; if (l == r) { tree[x].max = 0; return; } int mid = (l + r) >> 1; build(x << 1, l, mid); build(x << 1 | 1, mid + 1, r); push_up(x); }
inline void update(int x, int pos, int val) { int l = tree[x].l, r = tree[x].r; if (l == r) { tree[x].max = max(tree[x].max, val); return; } int mid = (l + r) >> 1; if (pos <= mid)update(x << 1, pos, val); else update(x << 1 | 1, pos, val); push_up(x); }
inline int query(int x, int l, int r) { int le = tree[x].l, ri = tree[x].r; if (l <= le && ri <= r) { return tree[x].max; } int mid = (le + ri) >> 1; int maxm = 0; if (l <= mid) maxm = max(maxm, query(x << 1, l, r)); if (r > mid) maxm = max(maxm, query(x << 1 | 1, l, r)); return maxm; } }
int t, n, m, a[10005], dp[10009][509]; string s; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) dp[i][j] = dp[i - 1][j - 1] + a[i]; dp[i][0] = dp[i - 1][0]; for (int j = 1; j <= i && j <= m; j++) dp[i][0] = max(dp[i][0], dp[i - j][j]); } cout << dp[n][0] << endl; }
|
近期评论