1 条题解
-
0Guest LV 0 MOD
-
1
#include <iostream> #include <cstring> #include <cmath> using namespace std; int f[105][10005], n, L, R, K, a[105]; int main() { cin >> n >> L >> R >> K; for (int i = 1; i <= n; i++) cin >> a[i]; memset(f, 0x3f, sizeof(f)); f[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = R - L; j >= 0; j--) { int v = abs(L + j - i); for (int k = 0; k <= K - v; k++) { f[j + 1][k + v] = min(f[j + 1][k + v], f[j][k] + a[i]); } } } int ans = 1 << 30; for (int i = 0; i <= K; i++) { ans = min(ans, f[R - L + 1][i]); } cout << ans << '\n'; return 0; }
- 1