Topic Portal
Sol: DP [i] is the maximum skill level before and after the i cows grouped by topic and requirements. Dp equation then becomes apparent;
- Dynamic Programming
#include "bits/stdc++.h" using namespace std; const int MAXN = 1e4 + 5; int arr[MAXN], dp[MAXN]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &arr[i]); for (int i = 1; i <= n; i++) { int _max = 0; for (int j = i; j > i - m && j > 0; j--) { _max = max(_max, arr[j]); dp[i] = max(dp[i], dp[j - 1] + (i - j + 1) * _max); } } printf("%d\n", dp[n]); return 0; }