Uva11400-lighting System design--[Dynamic Planning]

Source: Internet
Author: User

The problem is slightly dry.

Test Instructions Analysis:

It is easy to understand a class of light bulbs or all of them, in fact, the main reason for the cost savings is the replacement of the lamp type and eliminate the low voltage source, so we can infer the principle of lamp type substitution:

For two types of bulbs A1 and A2,A1 can be replaced by A2 conditions are:

1) v2>v1

2) A2 must exist in the optimal Jianzhong (guaranteed K2 not be omitted)

3) c2*l1-c1*l1-k1<0

Based on the above substitution principle, all lamp a1,a2,......,an are first sorted by voltage in a non-descending order, and we can assume that the state D[i] is the optimal solution (minimum cost) considering only the first 1~i bulb. When calculating d[i], only the AI substitution is considered, and the AI must exist in the optimal solution, satisfying the condition (1) (2). So the question is, what kind of replacement method is used? Here we consider the optimal solution of [i-1]:

Assuming the first i-1 bulb after the optimal replacement of the bulb sequence is B1,......,BJ,BJ+1,......BK (the voltage is not in descending order);

The relationship between BJ and Bj+1 must be satisfied: (1) cj+1*lj-cj*lj-kj>0 (otherwise BJ can be replaced by bj+1, with the assumption that the optimal solution is currently contradictory).

Now we consider the case of the I-bulb AI replacement, assuming that BJ can be replaced by AI, then there are (2) ci*lj-cj*lj-kj<0

By Inequality (1) (2) It is known that ci<cj+1, namely ci*lj+1-cj+1*lj+1-kj+1<0, bj+1 must be replaced by AI,

Similarly, all BJ~BK bulbs can be replaced by AI, in other words, in the optimal replacement sequence of i-1 bulbs B1~AJ~BK, if there is J (1<j<i-1), aj+1 can be replaced by AI, then

All AJ+1~BK bulbs can be replaced by AI, and the minimum cost of a1~aj bulbs has been calculated as d[j]. So we have the AI replacement method: The first J bulb with the best solution previously calculated d[j] buy, the rest of the j+1~i light bulbs are all used AI replacement, enumeration J from 0 to I-1, according to the previous discussion that does not leak, the state transfer equation d[j]=min{d[j]+c[i]* (s[ I]-S[J]) +k[i] | J from 0 to I-1},s[i] is the total number of first Class I bulbs.

The code is as follows:

1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 #defineMAXN 10006 intN;7 intv[maxn+5];8 intk[maxn+5];9 intc[maxn+5];Ten intl[maxn+5]; One intid[maxn+5]; A ints[maxn+5]; - intd[maxn+5]; - BOOLcmpintAintb) { the     returnv[a]<V[b]; - } - intdpinti) { -     intans=100000000; +      for(intj=0; j<i;j++) -Ans=min (ans,d[j]+c[id[i]]* (s[i]-s[j]) +K[id[i]]); +     returnans; A } at intMainintargcConst Char*argv[]) { -      while(SCANF ("%d", &n) = =1&&N) { -          for(intI=1; i<=n;i++) -scanf"%d%d%d%d",&v[i],&k[i],&c[i],&l[i]); -          for(intI=0; i<=n;i++) -id[i]=i; inSort (id+1, id+1+n,cmp); -s[0]=0; to          for(intI=1; i<=n;i++) +s[i]=s[i-1]+L[id[i]]; -d[0]=0; the          for(intI=1; i<=n;i++) *d[i]=DP (i); $printf"%d\n", D[n]);Panax Notoginseng     } -     return 0; the}

Uva11400-lighting System design--[Dynamic Planning]

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.