Dolls hdu 4160 匈牙利算法求出最大匹配值
2014-02-19 12:19
267 查看
Dolls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 929 Accepted Submission(s): 443
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.
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
The 2011
Syrian Collegiate Programming Contest
Recommend
lcy
这个题目还是比较好做的,这是我做的第一个二分匹配,题意是说有n个洋娃娃,
每个娃娃有长宽高,长宽高都大的可以包含小的,求有多少个在外面的,用匈牙利
算法求出最大匹配值,然后用n减去就的了
#include<stdio.h> #include<string.h> using namespace std; #define M 2000 int n; int link[M],g[M][M];//g[][]是算地图,link代表联系 bool vis[M]; struct node { int x,y,z; }box[M]; 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 num=0; for(int i=1;i<=n;i++) { memset(vis,false,sizeof(vis)); if(find(i)) { //printf("fdsjklfsd"); num++; } } printf("%d\n",n-num); } return 0; }
相关文章推荐
- 【2016-CCPC-K】匈牙利算法,最大基数匹配(Kingdom of Obsession,hdu 5943)
- 二分图最大匹配的匈牙利算法完整代码
- poj1274 匈牙利算法 二分图最大匹配
- hihocoder 1122最大二分匹配匈牙利算法
- 二分图的最大匹配--匈牙利匹配算法
- 二分图的最大匹配问题(匈牙利算法)
- 二分图的最大匹配、完美匹配和匈牙利算法
- 二分图的最大匹配 匈牙利算法
- 二分最大匹配 匈牙利算法
- HDU 1281 棋盘游戏(匈牙利算法 二分最大匹配)
- 二分图的最大匹配—匈牙利算法
- 匈牙利算法 求最大匹配
- 二分图匹配之最大匹配——匈牙利算法
- 模板_matlab 匈牙利算法(最大匹配数/最小覆盖点)
- 二分图的最大匹配、完美匹配和匈牙利算法
- 二分图匈牙利算法最大匹配及相关
- Pku acm 1469 COURSES 数据结构题目解题报告(十一)---- 匈牙利算法求二分图的最大匹配
- 无权二分图(最大匹配,完美匹配)(匈牙利算法)andSDNUOJ1247
- HDU 2063 过山车 [匈牙利算法之最大匹配问题]
- poj3041 匈牙利算法 二分图最大匹配