http://acm.hdu.edu.cn/showproblem.php?pid=4160
题意:每一个doll有三个属性:wi,li,hi,如果di、dj满足的wi < wj , li < lj , and hi < hj ,那么di可以放到dj里,并且每个doll最多只能装一个doll,求最外层的doll最少有多少个
分析:n-二分图的最大匹配
#include <iostream>
#include <cstdio>
using namespace std;
const int NM=505;
int a[NM][NM],link[NM],flag[NM],n;
struct Node{
int x,y,z;
}doll[NM];
int Find(int x)
{
for(int i=0;i<n;i++)
{
if(a[x][i]&&!flag[i])
{
flag[i]=1;
if(link[i]==-1||Find(link[i]))
{
link[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,ans;
while(scanf("%d",&n)&&n)
{
memset(a,0,sizeof(a));
memset(link,-1,sizeof(link));
for(i=0;i<n;i++)
{
scanf("%d%d%d",&doll[i].x,&doll[i].y,&doll[i].z);
for(j=0;j<i;j++)
{
if(doll[i].x<doll[j].x&&doll[i].y<doll[j].y&&doll[i].z<doll[j].z) //匹配规则
a[j][i]=1;
if(doll[i].x>doll[j].x&&doll[i].y>doll[j].y&&doll[i].z>doll[j].z)
a[i][j]=1;
}
}
ans=0;
for(i=0;i<n;i++)
{
memset(flag,0,sizeof(flag));
if(Find(i))
ans++;
}
printf("%d\n",n-ans);
}
return 0;
}