"Dynamic programming on linear structures" UVa 11400-lighting System Design

Source: Internet
Author: User

Problem F
Lighting systemdesign

Input: Standardinput

Output: StandardOutput

You is given the task to Designa lighting system for a huge conference hall. After doing a lot of calculation& sketching, you had figured out the requirements for an energy-efficientdesign that Can properly illuminate the entire hall. According to your design,you need lamps ofN Different powerratings. For some strange-regulation method, all the lamps need-befed with the same-amount of current. So, each category of lamp has acorresponding voltage rating. Now, your know the number of lamps & cost Ofevery single unit of lamp for each category. But the problem was, you were to buy equivalent voltage sources for all the lampcategories. You can buy a single voltage source for each category (each Sourceis capable of supplying to infinite number of lamps of I TS voltage rating.) & Complete the design. But the accounts sections of your company soonfigures out that they might is able to reduce the total system cost by elimin Atingsome of the voltage sources & replacing the lamps of that category Withhigher rating lamps. Certainly you can never replace a lamp by a lower ratinglamp as some portion of the hall might is illuminated then. You is moreconcerned about money-saving than energy-saving. Find the minimum possible costto design the system.

Input

Each case in the input beginswith N (1<=n<=1000), denoting the numberof categories. Each of the following n lines describes a category. A Categoryis described by 4 integers- V (1<=v<=132000), the voltage rating,k (1<=k<=1000), the cost of a voltage source of this rating, C (1<=c<=10), the cost of a lamp of this rating & L (1<=l<=100), the NUM ber of lamps required in the This category. The input terminates with a test case where n = 0. This case is should not beprocessed.

Output

For each test case, print the minimum possible cost todesign the system.

Sample input Outputfor Sample input

3

100 500 10 20

120 600 8 16

220 400 7 18

0

Read the question when test instructions understand not very good, see analysis only then understand. Gives n bulbs with four properties (V-voltage, K-Power cost, C-cost per bulb, L-required number of bulbs), and the most reasonable lighting system design that requires the least amount of money.

What you don't think about is that each voltage bulb is either full or not. Because if only a portion of the bulb is replaced by another bulb, you need to buy two different voltages of the power supply. It's not worth it. Moreover, the high voltage bulb, because the current size is equal, so the power is also big, this will save more money.

The code is simple:

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <algorithm>6 using namespacestd;7 Const intMAXN =1005;8 structLamp9 {Ten     intV, K, C, L; One     BOOL operator< (Constlamp& a)Const A     { -         returnV <A.V; -     } the }LAMP[MAXN]; - intDP[MAXN], SUM[MAXN]; - intMain () - { +     intN; -      while(~SCANF ("%d", &n) &&N) +     { A          for(inti =1; I <= N; i++) at         { -scanf"%d%d%d%d", &lamp[i]. V, &lamp[i]. K, &lamp[i]. C, &Lamp[i]. L); -         } -Sort (lamp+1, lamp+1+n); -memset (SUM,0,sizeof(sum)); -Memset (DP,0,sizeof(DP)); insum[0] =0; -          for(inti =1; I <= N; i++) to         { +Sum[i] = sum[i-1]+Lamp[i]. L; -             if(i = =1) Dp[i] = Lamp[i]. c*sum[i]+Lamp[i]. K; the             Else *              for(intj =0; J < I; J + +) $             {Panax Notoginseng                 if(Dp[i] = =0) Dp[i] = Dp[j]+lamp[i]. c* (Sum[i]-sum[j]) +Lamp[i]. K; -                 ElseDp[i] = min (Dp[j]+lamp[i]. c* (Sum[i]-sum[j]) +Lamp[i]. K, Dp[i]); the             } +         } Aprintf"%d\n", Dp[n]); the     } +     return 0; -}

"Dynamic programming on linear structures" UVa 11400-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.