Purple Book title:
Test instructions: let you design a lighting system that gives you n bulbs, each with a voltage, a power supply, the cost per bulb, and the quantity required for each bulb. Each bulb requires a different power supply, where a large voltage bulb can replace a small lamp with a low voltage, requiring minimum cost
The following: Each type of voltage bulb or all, or do not change, because the only part of the additional power costs, and replaced the part after the cost of less, as the full exchange
First the light bulb according to the voltage from small to large, so when the DP, the back of the voltage is greater than the voltage is more than the better words can be replaced
Set DP[J] for the first J, then dp[i] = Min{dp[i],dp[j] + (S[i]-s[j]) * C[i] + k[i]} Dp[i] before use to initialize to the maximum
S is the total number of previous I bulbs, s[i]-s[j] indicates that the replacement from I to J is the cost of (S[i]-s[j]) * C[i] + k[i] plus the cost of the first J bulbs Dp[j];
#include <iostream>#include<algorithm>#include<cmath>#include<cstring>#include<cstdio>#include<cstdlib>Const intINF =0xFFFFFFF;Const DoubleESP = 10e-8;Const DoublePi = Atan (1) *4;Const intMOD =1000007;Const intMAXN = ++Ten; typedefLong LongLL;using namespacestd;structlight{intv,k,c,l; BOOL operator< (light a)Const{ returnV <A.V; }}; Light LIGHT[MAXN]; LL DP[MAXN]; LL S[MAXN];intMain () {//freopen ("Input.txt", "R", stdin); intN; while(~SCANF ("%d", &n) &&N) { for(inti =1; I <= n;i++) {scanf ("%d%d%d%d",&light[i].v,&light[i].k,&light[i].c,&LIGHT[I].L); } Sort ( light+1, light+n+1); s[0] =0; for(inti =1; I <= n;i++) {S[i]= Light[i].l + s[i-1]; } dp[0] =0; for(inti =1; I <= n;i++) {Dp[i]=INF; for(intj =0; J <= i;j++) {Dp[i]= Min (dp[i],dp[j]+ (S[i]-s[j]) * light[i].c +LIGHT[I].K); }} printf ("%lld\n", Dp[n]); } return 0;}
UVA 11400 problem F Lighting System Design