In the best case, it is impossible to cross a light bulb. Why? Because it is cost-effective to replace a with C. If a with B, it is not cost-effective to replace a and B with C.
Then there is simple DP.
# Include <cstdio> # include <cstring> # include <iostream> # include <map> # include <set> # include <vector> # include <string> # include <queue> # include <deque> # include <bitset> # include <list> # include <cstdlib> # include <climits> # include <cmath> # include <ctime> # include <algorithm> # include <stack> # include <sstream> # include <numeric> # include <fstream> # include <functional> using namespace STD; # define MP make_pair # define Pb push_backtypedef long ll; typedef unsigned long ull; typedef vector <int> VI; typedef pair <int, int> PII; const int INF = int_max/3; const double EPS = 1e-8; const ll linf = 1e17; const double dinf = 1e60; const int maxn = 1005; struct lamp {int v, k, c, L; lamp (int v = 0, int K = 0, int C = 0, int L = 0): V (V), K (K ), C (c), L (l) {} bool operator <(const lamp & X) const {return v <X. V ;}}; lamp [maxn]; int N, cost [maxn], CNT [maxn]; int main () {While (scanf ("% d ", & N), n) {for (INT I = 1; I <= N; I ++) {int v, k, C, L; scanf ("% d", & V, & K, & C, & L); lamp [I] = lamp (v, k, C, l);} Sort (lamp + 1, lamp + 1 + n); For (INT I = 1; I <= N; I ++) CNT [I] = CNT [I-1] + lamp [I]. l; For (INT I = 1; I <= N; I ++) {cost [I] = inf; For (Int J = I; j> = 1; J --) {int nowval = cost [J-1] + (CNT [I]-CNT [J-1]) * lamp [I]. c + lamp [I]. k; cost [I] = min (cost [I], nowval) ;}} printf ("% d \ n", cost [N]);} return 0 ;}
Ultraviolet A 11400 lighting system design DP