1.6 beverage supply

Source: Internet
Author: User

Problem:

A total of n drinks, each represented as (s [I], V [I], C [I], H [I], B [I]), S represents the name, V indicates capacity, C indicates the maximum quantity that can be purchased, h indicates satisfaction, and B indicates the actual purchase volume.
When V [I] * B [I] summation = V, H [I] * B [I] summation is maximized.


Optimization, without a doubt, consider dynamic planning and greed.

State transition equation:

Set OPT (V', I) to indicate that CI is the maximum number of I-to n-1 drinks, calculate the maximum value of satisfaction in the total number of V' programs.

The recursive formula should be:

Opt (V', I) = max {K * Hi + OPT (V '-VI * k, I + 1)} (k =, 2 ..., CI, I = 0, 1, 2 ..., N-1)

Here I think the beverage combination that needs to be explained can finally be combined into v.



Recurrence:

Int Cal (int v, int t) {OPT [0] [T] = 0; // boundary condition, t is all types of drinks for (INT I = 0; I <= V; ++ I) OPT [I] [T] =-INF; // Boundary Condition for (Int J = T-1; j> = 0; -- J) {for (INT I = 0; I <= V; ++ I) {OPT [I] [J] =-INF; For (int K = 0; k <= C [J]; ++ K) {// traverse the number of selected J drinks Kif (I <K * V [J]) break; int x = OPT [I-V [J] * k] [J + 1]; If (X! =-INF) {x + = K * H [J]; If (x> OPT [I] [J]) OPT [I] [J] = x ;}}} return OPT [v] [0];}



Memory-based search:

Int OPT [V + 1] [t + 1]; // The value stored in OPT during initialization is-1, indicating that the subproblem has not been solved. Int CAL (int v, int type) {If (type = T) {If (V = 0) return 0; else return-INF;} If (v <0) Return-INF; if (V = 0) return 0; else if (OPT [v] [type]! =-1) return OPT [v] [type]; // If the subproblem has been solved, the int ret =-INF; // If the subproblem has not been solved, the subproblem for (INT I = 0; I <= C [type]; ++ I) {int temp = CAL (V-I * V [type], type + 1); If (temp! =-INF) {temp + = I * H [type]; If (temp> RET) ret = temp;} return OPT [v] [type] = ret ;}



1.6 beverage supply

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.