The main effect of the topic:
There are n pieces of furniture, each of which weighs (1≤wi≤100) and is transported to the destination with two handlebar vehicles. The two vehicles have a load limit of C1, C2 (1≤ci≤100), asking at least a few trips to get all the furniture to the destination.
The two cars must go with each other, even if a car is not carrying anything.
Ideas:
A
First on your own way:
Enumerating all the combinations of furniture that the first vehicle may carry, then a binary representation of the state is a total of 1<<n, and if the binary is 1, then the first piece of furniture is shipped.
This would be tantamount to dividing all the furniture into two groups, one for the first and the other for the second.
Then the two sets of data, respectively, can be transported at least several times, so that the problem is converted to: to n furniture, and a load of weight C of the car, the car at least several times can be carried out.
By the greedy thought can know that each delivery should be as full as possible to fill the car, then with 01 backpacks, backpack capacity to load the weight of C, the weight of each piece of furniture is the value is also cost, f[c] is this delivery. After the selection, the selected furniture removed, continue to do 01 backpack selection, until all the furniture selected. As for the records selected furniture, method and record path.
The two cars were then shipped in a larger number, the minimum number of times this was enumerated.
Two
This method is to learn, the basic online is this method, no longer fine talk.
The idea is to use the binary to express the choice of the state, the first pretreatment of all the selection of combinations, see whether the group selected furniture can be two cars once, if you can "pack" up as an object, and then to all the objects carry 01 backpacks.
Code:
Method One:
#include <iostream> #include <queue> #include <cstdio> #include <cstring> #include <CMATH&G
T #include <map> #include <vector> #include <string> #define MP make_pair #define SQ (x) ((x) * (x)) C
Onst Double PI = ACOs (-1.0);
const int INF = 0X3F3F3F3F;
using namespace Std;
typedef long long Int64;
const int MAXN = 12;
int n, m;
int C1, C2;
int f[110];
int W[MAXN];
int ans;
BOOL path[maxn][110];
VECTOR<INT>W1, W2; BOOL Check (int x) {for (int i=0; i<n; ++i) {if ((x>>i) &1) {if (W[I]>C1) return
False
}else{if (W[I]>C2) return false;
} return true;
} void init (int x) {w1.clear (); W2.clear ();
for (int i=0; i<n; ++i) {if ((x>>i) &1) {w1.push_back (w[i));
}else W2.push_back (W[i]); } void Update (VEctor<int>&w, int i, int j) {if (i<0) return;
int tmp = W[i];
if (Path[i][j]) {w.erase (W.begin () +i);
Update (w, i-1, j-tmp);
}else Update (W, I-1, J);
int counter (vector<int>& w, int c) {if (W.size () ==0) return 0;
int cnt = 0;
do{cnt++;
if (CNT >= ans) return CNT;
memset (f, 0, sizeof (f));
memset (path, 0, sizeof (path)); for (int i=0; i<w.size (); ++i) {for (int v=c; v>=w[i];--v) {if (f[v-w[i]]+w[i) >= F [v])
{F[v] = F[v-w[i]]+w[i];
PATH[I][V] = 1;
}} update (W, w.size ()-1, c);
}while (W.size ());
return CNT;
int main () {int ncase, Cas=1, X;
scanf ("%d", &ncase);
while (ncase--) {printf ("Scenario #%d:\n", cas++); scanf"%d%d%d", &N,&C1,&C2);
for (int i=0; i<n; ++i) scanf ("%d", &w[i]);
ans = INF;
int sta = 0;
while (STA < (1<<n)) {if (!check (STA)) {sta++;
Continue
Init (STA);
int cnt1 = Counter (W1, C1);
int cnt2 = counter (w2, C2);
ans = min (ans, max (cnt1, Cnt2));
sta++;
printf ("%d\n\n", ans);
return 0; }