解析:
将灯按v排序后记录一下数量的前缀和,然后dp就好了。
dp[i] = max(dp[j]+Ki+Ci*sigma(L[j+1...i]));
[code]:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define th(x) this->x=x;
using namespace std;
struct Node{
int v,k,c,l;
bool operator < (const Node &z)const{
return v < z.v;
}
}A[1005];
int n,sum[1005],dp[1005];
int main(){
int i,j,cas;
scanf("%d",&cas);
for(int T=1;T<=cas;T++){
scanf("%d",&n);
for(i = 1;i <= n;i++){
scanf("%d%d%d%d",&A[i].v,&A[i].k,&A[i].c,&A[i].l);
}
sort(A+1,A+n+1);
for(i = 1;i <= n;i++){
sum[i] = sum[i-1] + A[i].l;
}
for(i = 1;i <= n;i++){
dp[i] = A[i].k+A[i].c*sum[i];
for(j = 1;j < i;j++){
dp[i] = min(dp[i],dp[j]+A[i].k+A[i].c*(sum[i]-sum[j]));
}
}
printf("Case %d: %d\n",T,dp[n]);
}
return 0;
}