UVA 11400 Lighting System Design

Source: Internet
Author: User

Original question:
You is given the task to design a lighting system for a huge conference hall. After doing a lot of
Calculation and sketching, you are figured out of the requirements for a energy-efficient design that can properly illumin Ate the entire hall. According to your design, you need lamps of n different power ratings. For some strange-regulation method, all the lamps need-to is fed with the same amount of current. So, each category of lamp has a corresponding voltage rating. Now, your know the number of lamps and cost of every single unit of lamp for each category. But the problem was, you were to buy equivalent voltage sources for all the lamp categories. You can buy a single voltage source for each category (each source is capable the supplying to infinite number of lamps of Its voltage rating.) and complete the design. But the accounts sections of your company soon figures out that they might is able to reduce the total system cost by Elimi Nating Some of the voltage sources and replacing the lamps of that category with higher rating lamps. Certainly you can never replace a lamp by aLower rating lamp as some portion of the hall might not being illuminated then. Concerned about money-saving than energy-saving. Find the minimum possible cost to design the system.
Input
Each case in the input begins with N (1≤n≤1000), denoting the number of categories. Each of the
Following n lines describes a category. A category is described by 4 integers-v (1≤v≤132000), the voltage rating, K (1≤k≤1000), and the cost of a voltage so Urce of this rating, C (1≤c≤10), the cost of a lamp of this rating and L (1≤l≤100), the number of lamps required I n this category. The input
Terminates with a test case where n = 0. This case is should not being processed.
Output
For each test case, print the minimum possible cost to design the system.
Sample Input
3
100 500 10 20
120 600 8 16
220 400 7 18
0
Sample Output
778
Main topic:
Let you give a hall to install lighting system, give you n kinds of different lamps, each of which has the following data, voltage value, the price of the power supply, the cost of the lamp, the number of the need for this lamp. A power supply can supply countless lamps, all of which have the same current through the lamp. To save money, you can replace some lights with a high-voltage bulb instead (the price of a light bulb that is at a high voltage, the number remains the number of the bulb being replaced). Now ask you to install these numbers of lights, at least how much money.

 #include <bits/stdc++.h> using namespace std; const int inf=9999999; struct Light {int
v,k,c,l;
};
Light ls[1001];
int cmp (const light &L1,CONST light &l2) {return l1.v<l2.v;} int dp[1001];
    int main () {Ios::sync_with_stdio (false);
    int n; while (Cin>>n,n) {for (int i=1;i<=n;i++) cin>>ls[i].v>>ls[i].k>>ls[i].c&
        gt;>ls[i].l;
        Sort (ls+1,ls+1+n,cmp);
        Memset (Dp,0,sizeof (DP));
            for (int i=1;i<=n;i++) {dp[i]=inf;
            int tmp=0;
                for (int j=i;j>=1;j--) {tmp+=ls[j].l;
            Dp[i]=min (DP[I],DP[J-1]+TMP*LS[I].C+LS[I].K);
    }} cout<<dp[n]<<endl;
} return 0; }

parsing:
Simple one-dimensional dynamic programming problem, you can refer to the longest increment sub-sequence similar to the problem of the stacked box. First, according to the voltage value from small to large sequencing, because the voltage of the power supply can meet the voltage requirements of the bulb. Set status Dp[i] indicates the minimum amount of money that is spent on the first bulb. Next look for a state transfer, the transfer process only two, either with the current bulb to replace the back of the bulb (because of the order), or do not replace, if replaced, replace to the number of. There is a problem here, such as a light bulb needs 20, then if you want to replace the light bulb, is all replaced, or replace a part to find the best. The answer must be to replace all, because if the current bulb price is 1, the price to be replaced is 2, that would be 1 dollars cheaper, and can save a replacement bulb power money.
So

Dp[i]=min (DP[I],DP[J-1]+TMP*LIGHT[I].C+LIGHT[I].K)

Where Light[i] is the type I lamp, TMP indicates the number of bulbs calculated from the back of I, plus used to be replaced by the first bulb. So the equation means that the optimal value of the dp[i] is equal to the best value (1<=j<=i) when the first J bulb is replaced by the I-bulb replacement plus the j-1-light system.
Here is a point to think clearly, such as now 100 sequence of light bulbs, now to calculate dp[80], to the front to find the state, such as find dp[50], then acid dp[80] is equal to 80 to the 51st bulb is replaced by the 80th light bulb with dp[50], So whether there are any bulbs between 80 and 50 that do not use the 80th bulb instead to get the best value. Of course there is, because you have enumerated this state before you count to number 50th (for example, the 70th bulb, where the TMP is 80 to 71 bulbs instead of the 80th bulb with the dp[70], so continue to enumerate.

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.