UVA 11400 problem F Lighting System Design

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.