Uva-11400-lighting System Design

Source: Internet
Author: User

You is given the task to design a lighting system for a huge conference hall. After doing a lot of calculation & sketching, you had figured out the requirements for an energy-efficient design tha T can properly illuminate the entire hall. According to your design, you need lamps ofN 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 & cost of every single unit of lamp for each category. But the problem is, you is 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.) & 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 & replacing the lamps of this category with higher rating lamps. Certainly you can never replace a lamp by a lower rating lamp as some portion of the hall might is illuminated then. Concerned about money-saving than energy-saving. Find the minimum possible cost to Design the system.


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), the Cos T of a voltage source of this rating, C (1<=c<=10), the cost of a lamp of this rating & L (1<=l<=100), the Number of lamps required in this category. The input terminates with a test case where n = 0. This case is should not being processed.


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

Sample input Output for sample input


100 500 10 20

120 600 8 16

220 400 7 18



Dynamic planning.

First of all understand a little. Assuming a lamp needs to be replaced, this type of bulb will have to be switched all. Select State D[i] is the minimum cost of the bulb 1~i, the state transition equation is: d[i] = min (D[i], D[j] + (S[i]-s[j]) * lamp[i].c + LAMP[I].K); Represents the first J with the best scheme, the J = 1 ~ I all use the first type I power supply. Finally the answer is D[n].

AC Code:

#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring > #include <string> #include <sstream> #include <vector> #include <set> #include <map># Include <algorithm> #include <stack> #include <queue> #include <bitset> #include <cassert > #include <cmath> #include <functional>using namespace std;const int maxn = 1005;struct Lamp{int V, K, C, l ; bool operator < (const lamp& RHS) Const {return v < rhs.v;}} Lamp[maxn];int N, S[MAXN]; S[i] for the total number of previous I bulbs int D[MAXN]; D[i] for the minimum cost of the bulb 1~i void init () {for (int i = 1; I <= n; i++) {cin >> lamp[i].v >> lamp[i].k >> lamp[i]. c >> lamp[i].l;} Sort (lamp + 1, lamp + n + 1); Note the sort range s[0] = 0;for (int i = 1; I <= n; i++) {s[i] = s[i-1] + lamp[i].l;}} void Solve () {d[0] = 0;for (int i = 1; I <= n; i++) {d[i] = s[i] * lamp[i].c + lamp[i].k;//Front I bulb buy-all type ifor (int j = 1; j <= i; J + +) {D[i] = min (D[i], D[j] + (S[i]-s[j]) * lamp[i].c + LAMP[I].K);}} cout << D[n] << Endl;} int main () {Ios::sync_with_stdio (false), while (CIN >> n && N) {init (); Solve ();} return 0;}

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.