1392 box Base time limit: 1 seconds space limit: 131072 KB score: 160 Difficulty: 6-level algorithm problem collection attention to have n rectangular box, the length of the i is Li, the width of WI, we need to put them in a set. Note that a box can only fit into a box with a length and width that is not smaller than its height, and that a box can only be loaded directly into another box (but is constantly nested), such as 1 * 1 can be set into 2 * 1, and 2 * 1 is then set into 2 * 2. The box covers an area of the outermost box after it is set in. Given the size of the N box, the final minimum total floor area is obtained. Input
The first row, a number n, indicates the number of boxes. The next n lines, two positive integers per line, represent the length and width of each box. All integers are positive (N, and the length and width of the box), and no more than 200.
Output
An integer line represents the final minimum footprint.
Input example
31 11 22 1
Output example
4
The two boxes can be loaded with one edge, then the size of the box according to the size of the maximum matching of the binary map, matching the total area of a successful match-loaded box area.
Code:
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string > #include <cstring> #pragma warning (disable:4996) using namespace Std;int grid[805][805];int link[805];int Visit[805];int N, sum2, V1, v2;struct no {int x;int y;} Node[205];bool CMP (const no&node1,const no&node2) {return node1.x*node1.y < node2.x*node2.y;} bool Dfs (int x) {int i;for (i = V2; i>=1; i--) {if (Grid[x][i] && visit[i] = = 0) {Visit[i] = 1;if (Link[i] = = 1 | | DFS (Link[i])) {Link[i] = X;return true;}}} return false;} void Magyarors () {int I;memset (link,-1, sizeof);//!! This cannot be 0 for (i = V1; i>=1; i--) {memset (visit, 0, sizeof (visit)), if (Dfs (i)) {sum2 = Sum2-node[i].x*node[i].y;}} cout << sum2 << Endl;} int main () {//freopen ("I.txt", "R", stdin);//Freopen ("O.txt", "w", stdout); int i,j,sum=0;scanf ("%d", &n); V1 = V2 = N;for (i = 1; I <= n; i++) {scanf ("%d%d", &node[i].x,&node[i].y); sum2 + = Node[i].x*node[i].y;} Sort (node+ 1, node + n + 1, CMP); for (i = 1; I <= n; i++) {for (j = i+1; J <= N; j + +) {if (node[j].x >= node[i].x&&n Ode[j].y >= node[i].y) {grid[i][j] = 1;}}} Magyarors (); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
51nod 1392: Packed box Hungarian + greedy