Lightoj 1295 Lighting System Design DP

Source: Internet
Author: User

Links: http://lightoj.com/volume_showproblem.php?problem=1295

1295-lighting System Design
PDF (中文版) Statistics Forum
Time Limit: 2 second (s) Memory Limit: MB

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 and cost of every single unit of lamp for each category. But the problem is, and that's 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) 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 a lower rating lamp as some portion of the hall might is illuminated then. Concerned about money-saving rather than energy-saving. Find the minimum possible cost toDesign the system.

Input

Input starts with an integer T (≤100), denoting the number of test cases.

Each case is starts with a line containing an integer n (1≤n≤1000). Each of the next n lines contains IV integers Vi, Ki, Ci and Li (1≤vi≤105, 1≤ki≤1000, 1≤c I≤10, 1≤li≤100). Here the integers- ith line has the following meaning.

1. Vi means the voltage rating,

2. Ki means the cost of a voltage source of this category,

3. Ci means the cost of a lamp of this category and

4. Li means the number of required lamps of this category.

You can assume this voltage rating for the categories would be distinct.

Output

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

Sample Input Output for Sample Input

1

3

100 500 10 20

120 600 8 16

220 400 7 18

Case 1:778



Test instructions

There are several lights, each lamp has four values

V the lamp voltage, can buy a high voltage bulb instead of a low-voltage bulb. Voltage 22 different

K generator Price, only one, you can supply an unlimited number of this voltage bulb.

C Bulb Price

L How much does this voltage bulb need

Ask for the minimum cost of buying all the required bulbs


Practice

Because high voltages can replace low-voltage bulbs, high voltages can be used to determine whether or not to buy a generator.

So first by the voltage order, then the back must be able to replace the previous one.

The prefix and sum array for the number of bulbs under preprocessing.

Then for Layer Two,

Dp[i]=min (dp[i],dp[j]+la[i].k+la[i].c* (sum[i]-sum[j));

Said bought I generator, Dp[j] said buy the best solution of the first J bulb, and then add the money to buy a generator, plus buy the rest of the bulb money, is the total cost. The minimum value is the optimal solution for the first I bulb.



#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include < malloc.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream># Include <algorithm>using namespace std, #include <stack> #include <queue> #include <vector># Include <deque> #include <set> #include <map> struct lamp {int v,k,c,l;}; Lamp la[1010];int sum[1010];int dp[1010];int cmp (lamp A,lamp b) {return A.V&LT;B.V;} int main () {int t;int cas=1;scanf ("%d" , &t), while (t--) {int n;scanf ("%d", &n), and for (int i=1;i<=n;i++) {scanf ("%d%d%d%d", &AMP;LA[I].V,&AMP;LA[I].K , &AMP;LA[I].C,&AMP;LA[I].L);} Sort (la+1,la+n+1,cmp); sum[0]=0;for (int i=1;i<=n;i++) Sum[i]=sum[i-1]+la[i].l;memset (dp,0x7f7f7f7f,sizeof dp);//printf ("%d\n", dp[1]); dp[0]=0;for (int i=1;i<=n;i++) {for (int j=0;j<i;j++) {dp[i]=min (dp[i],dp[j]+la[i].k+la[i].c* (Sum[i]-sum[j]));}} printf ("Case%d:%d\n", Cas++,dp[n]); }return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Lightoj 1295 Lighting System Design DP

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.