First is a greedy, a light bulb either all change, or all do not change.
First sort, define the state D[i] is the minimum cost of the preceding I bulbs, the state transfer is from the D[j],j<i, plus I front of the j+1 to i-1 bulbs to replace the cost of I.
Subscript Sort Play off ...
#include <bits/stdc++.h>using namespacestd;Const intMAXN = 1e3+3;intV[MAXN], K[MAXN], C[MAXN], L[MAXN];intD[MAXN],R[MAXN],S[MAXN];BOOLcmpintAintb) {returnv[a]<v[b];}intMain () {//freopen ("In.txt", "R", stdin); intN s[0] =0; while(SCANF ("%d",&N), N) { for(inti =1; I <= N; i++) {scanf ("%d%d%d%d", v+i,k+i,c+i,l+H); R[i]=i; } sort (R+1, r+1+n,cmp); for(intID =1; ID <= N; id++){ inti =R[id]; S[id]= s[id-1] +L[i]; D[id]= S[id]*c[i] +K[i]; for(intId2 =1; Id2 < ID; id2++){ intj =R[id2]; D[id]= Min (d[id],d[id2]+ (S[id]-s[id2]) *c[i]+K[i]); }} printf ("%d\n", D[n]); } return 0;}
UVA 11400 Lighting System Design Lighting Systems