Ultraviolet A 11400-lighting system design (the longest rising sub-sequence problem variant in Dynamic Planning)

Source: Internet
Author: User

The difficulty of this question seems to be that some bulbs can be replaced with bulbs with higher voltage to save money on power supply, so we have to explore the optimal solution.

A good solution is to sort the voltage from small to large, so we can only replace the previous one with the following one.Change some bulbs to bulbs with higher voltageRequirements;

A voltage bulb can be switched either. If it is to be switched, it should be switched. If it is to be switched, it means that the current power supply is not worth it. If it is not worth it, it should be switched out to avoid using the current power supply, otherwise, the lightbulb cost will be increased, and the power cost will not be reduced...

For details about status transfer, refer to the code.

# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 1010; struct lamp {int v, k, C, L ;} A [maxn]; int N, V1, K1, C1, L1; int s [maxn]; int d [maxn]; bool CMP (lamp A1, lamp A2) {return a1.v <a2.v;} int main () {While (scanf ("% d", & N )! = EOF) {If (n = 0) break; memset (S, 0, sizeof (s); memset (D, 0, sizeof (d )); memset (A, 0, sizeof (a); For (INT I = 1; I <= N; I ++) {scanf ("% d", & V1, & K1, & C1, & L1); A [I]. V = V1; A [I]. k = k1; A [I]. C = C1; A [I]. L = L1;} Sort (a + 1, A + n + 1, CMP); s [0] = 0; For (INT I = 1; I <= N; I ++) {s [I] = s [I-1] + A [I]. l;} d [0] = 0; For (INT I = 1; I <= N; I ++) {for (Int J = 0; j <I; j ++) {If (j =-0) d [I] = (s [I]) * A [I]. c + A [I]. k; else d [I] = min (d [J] + (s [I]-s [J]) * A [I]. c + A [I]. k, d [I]) ;}} printf ("% d \ n", d [N]);} return 0 ;}


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.