Lighting System Design UVA 11400 (dp+ thinking)

Source: Internet
Author: User
Tags min

The main topic: there is a lighting system need to use n kinds of lamps, each lamp voltage is V, power cost k, each bulb cost C, the number of lamps required is L. Note that the same voltage bulb only needs to share a corresponding power, and the low voltage bulb can be replaced by a high voltage bulb. In order to save cost, you will design a system to make the most inexpensive.
Analysis: The first need to clear a light bulb or all, or do not change. If you change a part, the first power costs are not saved, then the savings are only from the part of the light bulb, since you can save money why not simply all changed?
Once this is clear,
We should make certain restrictions on the decision: the minimum cost of the first I bulb, only allow the replacement of the first light bulb! How to replace it. can only replace 1 to I in serial number of light bulbs ... That is, the decision should be to choose a J, replace all the light bulbs with the number J to i-1, so that the first bulb cost is minimal. Then the final dp[n] is the answer.
D[i] to consider only the minimum cost of the first I bulbs, the state transfer equation: d[i] = Min{d[i] + (S[i]-s[j]) * C[i] + k[i]} where S[i] is the total number of bulbs of the former I.

But is it correct to do so, first of all, the above method in seeking the minimum cost of the first I bulb, can only be replaced with the first light bulb, this does not affect, because through the cycle of all the bulbs will be used to replace. The problem is that only the replacement of a continuous interval bulb causes the loss of the solution. For example, will not appear the optimal solution is the sequence number is 1, 3 of the bulb is replaced by a lamp, the number 2 is replaced by another or not replaced. Assuming that this is the minimum cost, then the replacement of the bulb 2 of the unit price must be less than the replacement of the bulb 1 of the unit price, otherwise it will not be the minimum value, since the replacement sequence 2 of the lamp unit price is less than the replacement number 1 lamp unit price, then replace the 2 bulb to replace the lamp 1, will produce a smaller This is inconsistent with assumptions, so the hypothesis is not true, that is, the previous decision will not miss the answer.

 #include <bits/stdc++.h> #define LL Long long #define PB push_back #define INF 0x3f3f3f3f # Define PLL pair<ll,ll> #define REP (i,a,b) for (int. i=a;i<=b;i++) #define REP1 (I,A,B) for (int i=a;i>=b;i--) #de
Fine Rson rt<<1|1,m+1,r #define Lson rt<<1,l,m using namespace std;
const int n=1e3+100;
ll Dp[n],s[n]; struct Node {ll v,k,c,l;}
App[n];
    BOOL CMP (node A,node b) {return a.v<b.v;} int main () {Ios::sync_with_stdio (false);
    int n; while (Cin>>n&&n) {rep (i,1,n) Cin>>app[i].v>>app[i].k>>app[i].c>>
        ; app[i].l;
        Sort (app+1,app+1+n,cmp);
        Rep (i,1,n) s[i]=s[i-1]+app[i].l;
            Rep (i,1,n) {dp[i]=app[i].k+app[i].c*s[i];
        Rep (j,0,i-1) dp[i]=min (dp[i],dp[j]+ (s[i]-s[j]) *APP[I].C+APP[I].K);
    } cout<<dp[n]<<endl;
} return 0; }

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.