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