HDU 4160 Dolls 匈牙利算法求最大匹配数
2013-07-30 16:07
274 查看
点击打开链接
Total Submission(s): 811 Accepted Submission(s): 378
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
1
3
2
[align=left]Source[/align]
The 2011 Syrian Collegiate Programming Contest
[align=left]Recommend[/align]
lcy
题意:有n个dolls,每个dolls都有长宽高。如果一个dolls的长宽高大于另一个dolls的长宽高,则较小的dolls可以放进较大的dolls里面,并且每个dolls里面只能放一个。让你求最外层的dolls有几个?
用总的dolls减去最大匹配的dolls。
Dolls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 811 Accepted Submission(s): 378
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
1
3
2
[align=left]Source[/align]
The 2011 Syrian Collegiate Programming Contest
[align=left]Recommend[/align]
lcy
题意:有n个dolls,每个dolls都有长宽高。如果一个dolls的长宽高大于另一个dolls的长宽高,则较小的dolls可以放进较大的dolls里面,并且每个dolls里面只能放一个。让你求最外层的dolls有几个?
用总的dolls减去最大匹配的dolls。
#include<stdio.h> #include<string.h> using namespace std; int n; int link[1007],g[1007][1007]; bool vis[1007]; struct node { int x,y,z; }box[1007]; bool judge(int i, int j) { if(box[i].x<box[j].x&&box[i].y<box[j].y&&box[i].z<box[j].z) return true; return false; } bool find(int i) { for(int j=1;j<=n;j++) if(g[i][j]&&!vis[j]) { vis[j]=true; if(link[j]==0||find(link[j])) { link[j]=i; return true; } } return false; } int main() { while(scanf("%d",&n),n) { memset(g,0,sizeof(g)); memset(link,0,sizeof(link)); for(int i=1;i<=n;i++) scanf("%d%d%d",&box[i].x,&box[i].y,&box[i].z); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(judge(i,j)) g[i][j]=1; int count=0; for(int i=1;i<=n;i++) { memset(vis,false,sizeof(vis)); if(find(i)) count++; } printf("%d\n",n-count); } return 0; }
相关文章推荐
- hdu 1054 Strategic Game(模板) 最大二分匹配,最小点覆盖 匈牙利算法
- hdu 1068 二分图的最大匹配匈牙利算法
- HDU 2063 匈牙利算法二分图的最大匹配
- 匈牙利算法,二分图最大基数匹配(过山车,hdu 2063)
- HDU 1150 Machine Schedule(匈牙利算法 二分图的最小顶点覆盖 二分图最大匹配)
- HDU 1281 棋盘游戏(匈牙利算法 二分最大匹配)
- 二分图最大匹配【匈牙利算法】HDU-1083
- hdu 2063 最大二分匹配,匈牙利算法
- HDU 2063 过山车(二分图最大匹配问题,匈牙利算法)
- HDU 2063过山车 二分图最大匹配 匈牙利算法
- HDU--3081--Marriage Match II--最大匹配,匈牙利算法
- hdu 2063(二分图最大匹配,匈牙利算法,水题)
- 【最大二分匹配匈牙利算法】hdu 3729
- HDU 2063 过山车(匈牙利算法 二分图的最小顶点覆盖 二分图最大匹配)
- HDU 1498 50 years, 50 colors(匈牙利算法 二分最大匹配数)
- hdu 4619 匈牙利算法 求最大匹配 2013 Multi-University Training Contest 2
- HDU--3081--Marriage Match II--最大匹配,匈牙利算法
- HDU-3605 Escape(状态压缩+最大流求多重匹配、改版匈牙利算法)
- hdu 1528 Card Game Cheater(二分图的最大匹配,匈牙利算法)
- HDU——1054 Strategic game(匈牙利算法(最大匹配))