The package can bear 15kg of the weight. The quality of five objects is 12, 2, 1, 4, and 1. The price is, and 1. the maximum value of the package is
Problem Analysis:
1. first obtain the bid value = GRID/weight and save it in an array;
2. Sort elements in a logarithm group in ascending order of values.
3. From the beginning of high-value installation, the problem of the backpack can be divided into the problem of cutting and not cutting backpack Problems
- // Question about the detachable backpack
- # Include <iostream>
- Using namespace STD;
- Class
- {
- Public:
- Int P, W;
- Double V;
- };
- Int main ()
- {
- A f [5], T;
- Int I, j, S, M, N, sum;
- Cin> N;
- For (I = 0; I <5; I ++)
- {
- Cin> F [I]. P> F [I]. W;
- F [I]. V = (double) f [I]. P/(double) f [I]. W;
- }
- For (I = 0; I <5; I ++)
- For (j = 0; j <5; j ++)
- {
- If (F [I]. V> F [J]. V)
- {
- T = f [I];
- F [I] = f [J];
- F [J] = T;
- }
- }
- S = 0;
- M = 0;
- Sum = 0;
- For (I = 0; I <5; I ++)
- {
- S = S + F [I]. W;
- If (n> S)
- {
- M = n-s;
- Sum = sum + F [I]. P;
- }
- Else
- Sum = sum + F [I]. V * m;
- }
- Cout <sum <Endl;
- Return 0;
- }
- Unpartitioned backpack
- # Include <iostream>
- Using namespace STD;
- Class
- {
- Public:
- Int P, W;
- Double V;
- };
- Int main ()
- {
- A f [5], T;
- Int I, j, S, M, N;
- Cin> N;
- For (I = 0; I <5; I ++)
- {
- Cin> F [I]. P> F [I]. W;
- F [I]. V = (double) f [I]. P/(double) f [I]. W;
- }
- For (I = 0; I <5; I ++)
- For (j = 0; j <5; j ++)
- {
- If (F [I]. V> F [J]. V)
- {
- T = f [I];
- F [I] = f [J];
- F [J] = T;
- }
- }
- S = 0;
- M = 0;
- For (I = 0; I <5; I ++)
- {
- S = S + F [I]. W;
- If (S> N) break;
- M = m + F [I]. P;
- }
- Cout <m <Endl;
- Return 0;
- }