11400-lighting System Design (DP)

Source: Internet
Author: User

The problem with voltage V, so that the enumeration ordered, for each kind of bulb, how to determine whether to use it? How to form recursion?

We know that recursion is to use the values that have been stored well before to determine the current optimal solution, so we use d[i] to indicate the minimum cost of 1~i bulbs.

Since each bulb is either used or replaced by another bulb, d[i] = min (D[i],d[j] + (S[i]-s[j]) *a[i].c + A[I].K); Where J < I means that the first J first buy with the best plan, and then the first j+1~i to use the No. I bulb.

Because the nth lamp voltage is the highest, can not be replaced by other bulbs, so there must be this light bulb, obviously this recursive relationship is rigorous. It makes perfect use of all the previously stored optimal solutions.

See the code for details:

#include <bits/stdc++.h>using namespace Std;const int maxn = + 10;const int INF = 2000000000;int N,d[maxn],s[max n];struct node{    int v,k,c,l;} A[maxn];bool CMP (node A,node b) {    return a.v < B.V;} int main () {    while (~scanf ("%d", &n) &&n) {for        (int i=1;i<=n;i++) scanf ("%d%d%d%d", &A[I].V, &A[I].K,&A[I].C,&A[I].L);        Sort (a+1,a+1+n,cmp);        S[0] = 0; D[0] = 0;        for (int i=1;i<=n;i++) s[i] = s[i-1] + a[i].l;        for (int i=1;i<=n;i++) {            d[i] = INF;            for (int j=0;j<i;j++) {                D[i] = min (D[i],d[j] + (S[i]-s[j]) *a[i].c + A[I].K);            }        }        printf ("%d\n", D[n]);    }    return 0;}


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

11400-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.