设dp[i][j],表示前i个位置,花费为j,的最大有趣指数。
然后类似背包一样转移。
/* Telekinetic Forest Guard */
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1005, maxm = 10005;
int L, n, m, dp[maxn][maxn];
struct _data {
int l, r, w, c;
bool operator < (const _data &x) const {
return l < x.l;
}
} track[maxm];
inline int iread() {
int f = 1, x = 0; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return f * x;
}
int main() {
L = iread(); n = iread(); m = iread();
for(int i = 1; i <= n; i++) track[i].l = iread(), track[i].r = track[i].l + iread(), track[i].w = iread(), track[i].c = iread();
sort(track + 1, track + 1 + n);
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for(int i = 1; i <= n; i++)
for(int j = track[i].c; j <= m; j++) if(~dp[track[i].l][j - track[i].c])
dp[track[i].r][j] = max(dp[track[i].r][j], dp[track[i].l][j - track[i].c] + track[i].w);
int ans = -1;
for(int i = 1; i <= m; i++) ans = max(ans, dp[L][i]);
printf("%d\n", ans);
return 0;
}