HDU 4160 (ZZULI 1598) Dolls(二分…
来源:互联网 发布:yii2.0框架源码下载 编辑:程序博客网 时间:2024/06/05 08:53
Dolls
Time Limit:1000MS Memory Limit:65536K
Total Submit:48 Accepted:16
Description
Do you remember the box ofMatryoshka dolls last week? Adam just got another box of dolls fromMatryona. This time, the dolls have different shapes and sizes:some are skinny, some are fat, and some look as though they wereattened. Specifically, doll i can be represented by three numberswi, li, and hi, denoting its width, length, and height. Doll i canfit 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 insideanother. Of course, each doll may contain at most one doll rightinside it. Your goal is to fit dolls inside each other so that youminimize the number of outermost dolls.
Input
The input consists ofmultiple test cases. Each test case begins with a line with asingle integer N, 1 ≤ N ≤ 500, denoting the number of Matryoshkadolls. Then follow N lines, each with three space-separatedintegers wi, li, and hi (1 ≤ wi; li; hi ≤ 10,000) denoting the sizeof the ith doll. Input is followed by a single line with N = 0,which should not be processed.
Output
For each test case, printout a single line with an integer denoting the minimum number ofoutermost dolls that can be obtained by optimally nesting the givendolls.
SampleInput
35 4 827 10 10100 32 52331 2 12 1 11 1 241 1 12 3 23 2 24 4 40
SampleOutput
132
Hint
此题正确解法为二分图匹配
Source
这题本来以为是贪心呢,结果比赛的时候无论怎么做都提交不上,郁闷死了,快,后来听学长说是二分匹配最后看了二分匹配的算法才AC了
代码:
#include<stdio.h>
#include<string.h>
intflag[501],match[501][501],vis[501],n;
structnode{
intx,y,z;
}map[501];
intOK(int i,int j)
{
if(map[j].x<map[i].x&&map[j].y<map[i].y&&map[j].z<map[i].z)
return1;
return0;
}
intDFS(int k)
{
inti,j;
for(i=0;i<match[k][0];i++)
{
j=match[k][i];
if(!vis[j])
{
vis[j]=1;
if(!flag[j]||DFS(flag[j]))
{
flag[j]=k;
return1;
}
}
}
return0;
}
intmain()
{
inti,j,num;
while(scanf("%d",&n),n)
{
for(i=0;i<n;i++)
{
scanf("%d%d%d",&map[i].x,&map[i].y,&map[i].z);
match[i][0]=0;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(OK(i,j))
match[i][match[i][0]++]=j;
num=0;
memset(flag,0,sizeof(flag));
for(i=0;i<n;i++)
{
memset(vis,0,sizeof(vis));
if(DFS(i))
num++;
}
printf("%d\n",n-num);
}
return0;
}
- HDU 4160 (ZZULI 1598) Dolls(二分…
- HDU 3123(ZZULI 1605) GCC(递推) …
- ZZULI 1619 (HDU 2647) Reward …
- HDU 1051(ZZULI 1609) Wooden St…
- ZZULI 1617 (HDU 1686)Oulipo (…
- ZZULI 1618 (HDU 1082)Matrix Ch…
- HDU 1150 Machine Schedule(二分…
- ZZULI 1615 easy or puzzle ?(字…
- ZZULI_SummerPractice(3) HDU 1…
- HDU 1083 Courses (二分匹配)
- HDU 1075 What Are You Talking …
- ZZULI 1595 Pills
- ZZULI 1498 做梦!
- ZZULI 等差数列 解题报告
- ZZULI 1497 Reading Books
- ZZULI 1616(POJ 2243||HDU 1372)…
- hdu 2039 三角形 /…
- hdu 1303 doubles …
- ZOJ 1504(POJ 1244) Slots of Fun…
- 【转载】C++静态成员函数小结
- HDU 3123(ZZULI 1605) GCC(递推) …
- ZOJ 1539(ZZULI 1606) LOT (递…
- HDU 1051(ZZULI 1609) Wooden St…
- HDU 4160 (ZZULI 1598) Dolls(二分…
- HDU 1083 Courses (二分匹配)
- 2012年3月份编程语言排行榜
- ZOJ 1060 (POJ 1094) Sorting It …
- POJ 2594 Treasure Exploration(…
- 关于在某些双卡手机上,联通卡抓包抓不到的情况及原因!
- POJ 3660 Cow Contest(关系闭包…
- HDU 1704 Rank (关系闭包)
- 腾讯、科大讯飞、小恩爱招聘信息