S S1 V1 S2 V2 is known; x S1 and Y S2 are available; x * S1 + y * S2 is used to evaluate max (x * V1 + y * V2)
Give a backpack the capacity n, the cost of the two items A, C, and value B, d, and ask how much value can be loaded at most.
Analysis: N/(A * C/gcd (a, c)-1 A, C, the minimum public factor of the backpack capacity must be the one with relatively high value, the remaining items that are expensive are enumerated to find the maximum value of the remaining item.
# Include "stdio. H"
# Include "string. H"
# Define max (A, B) A> B? A: B
_ Int64 fun (_ int64 A ,__ int64 B)
{
_ Int64 C, D = 1;
If (A <B)
{
C =;
A = B;
B = C;
}
While (D> 0)
{
D = A % B;
A = B;
B = D;
}
Return;
}
Int main ()
{
_ Int64 S, S1, S2, V1, V2, n, m, TMP, res, T, Max;
Int K, I, r = 1;
Scanf ("% d", & K );
While (k --)
{
Scanf ("% i64d % i64d % i64d % i64d % i64d", & S, & S1, & V1, & S2, & V2 );
TMP = S1/Fun (S1, S2) * S2;
N = s/tmp, M = S % TMP;
If (N)
{
N --;
M + = TMP;
}
Res = max (N * (TMP/S1) * V1, N * (TMP/s2) * V2 );
If (S1 <S2)
{
T = S1; S1 = S2; S2 = T;
T = V1; V1 = V2; v2 = T;
}
Max = 0;
For (I = 0; I <= m/S1; I ++)
{
T = I * V1 + (M-I * S1)/s2 * V2;
If (max <t)
Max = T;
}
Printf ("case # % d: % i64d \ n", r ++, Max + Res );
}
Return 0;
}