类似于LIS的递推,难在一个不等式的证明,这一点这篇博客写的很好,极力推荐​​点击打开链接​

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1010;
const int INF = 0x3f3f3f3f;
int n, cnt[maxn], dp[maxn];
struct Date {
int v, k, c, l;
bool operator < (const Date &d) const {
return v < d.v;
}
}date[maxn];
int main() {
while (~scanf("%d", &n) && n) {
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &date[i].v,&date[i].k,&date[i].c,&date[i].l);
}
sort(date+1, date+1+n);
cnt[0] = 0;
for (int i = 1; i <= n; i++) cnt[i] = cnt[i-1] + date[i].l;
memset(dp, INF, sizeof(dp));
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
dp[i] = min(dp[i], dp[j]+(cnt[i]-cnt[j])*date[i].c+date[i].k);
}
}
printf("%d\n", dp[n]);
}
return 0;
}