hdu 4160 Dolls
Dolls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 914 Accepted Submission(s): 433
Problem Description
Do you remember the box of Matryoshka dolls last week? Adam just got another box of dolls from Matryona. This time, the dolls have different shapes and sizes: some are skinny, some are fat, and some look as though they were attened. Specifically, doll i can be represented by three numbers wi, li, and hi, denoting its width, length, and height. Doll i can fit inside another doll j if and only if wi < wj , li < lj , and hi < hj .
That is, the dolls cannot be rotated when fitting one inside another. Of course, each doll may contain at most one doll right inside it. Your goal is to fit dolls inside each other so that you minimize the number of outermost dolls.
That is, the dolls cannot be rotated when fitting one inside another. Of course, each doll may contain at most one doll right inside it. Your goal is to fit dolls inside each other so that you minimize the number of outermost dolls.
Input
The input consists of multiple test cases. Each test case begins with a line with a single integer N, 1 ≤ N ≤ 500, denoting the number of Matryoshka dolls. Then follow N lines, each with three space-separated integers wi, li, and hi (1 ≤ wi; li; hi ≤ 10,000) denoting the size of the ith doll. Input is followed by a single line with N = 0, which should not be processed.
Output
For each test case, print out a single line with an integer denoting the minimum number of outermost dolls that can be obtained by optimally nesting the given dolls.
Sample Input
3
5 4 8
27 10 10
100 32 523
3
1 2 1
2 1 1
1 1 2
4
1 1 1
2 3 2
3 2 2
4 4 4
0
Sample Output
1
3
2
Source
Recommend
1 //93MS 1232K 1003 B C++ 2 /* 3 题意: 4 n个箱子,每个箱子里可以容下一个箱子,前提是长宽高 5 都小于该箱子,可重叠。问放完后最外面的箱子最少有几个 6 7 二分匹配匈牙利模板题: 8 先按条件构图,然后直接模板.. 9 */ 10 #include<stdio.h> 11 #include<string.h> 12 #define N 505 13 int g[N][N]; 14 int vis[N]; 15 int match[N]; 16 int w[N],l[N],h[N],n; 17 int dfs(int x) 18 { 19 for(int i=0;i<n;i++){ 20 if(!vis[i] && g[x][i]){ 21 vis[i]=1; 22 if(match[i]==-1 || dfs(match[i])){ 23 match[i]=x; 24 return 1; 25 } 26 } 27 } 28 return 0; 29 } 30 int hungary() 31 { 32 int ans=0; 33 memset(match,-1,sizeof(match)); 34 for(int i=0;i<n;i++){ 35 memset(vis,0,sizeof(vis)); 36 if(dfs(i)){ 37 //printf("*%d\n",i); 38 ans++; 39 } 40 } 41 return ans; 42 } 43 int main(void) 44 { 45 while(scanf("%d",&n),n) 46 { 47 memset(g,0,sizeof(g)); 48 for(int i=0;i<n;i++) 49 scanf("%d%d%d",&w[i],&l[i],&h[i]); 50 for(int i=0;i<n;i++) 51 for(int j=0;j<n;j++) 52 if(w[i]>w[j] && l[i]>l[j] && h[i]>h[j]) 53 g[i][j]=1; 54 printf("%d\n",n-hungary()); 55 } 56 return 0; 57 }