题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4160
题解:将所有doll看作点,能嵌套的doll之间连一条线(匹配),问题转化为二分图最大独立集
#include <cstdio>
#include <cstring>
#include <vector>
#define MAXN 502
using namespace std;
struct node
{
int x,y,z;
}dolls[MAXN];
vector<int>map[MAXN];
int from[MAXN],used[MAXN];
int match(int x)
{
for(int i=0;i<map[x].size();++i)
{
if(!used[map[x][i]])
{
used[map[x][i]]=1;
if(from[map[x][i]]==-1||match(from[map[x][i]]))
{
from[map[x][i]]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int n,i,j,ans;
while(scanf("%d",&n)&&n)
{
ans=0;
memset(from,-1,sizeof(from));
for(i=0;i<MAXN;++i)
map[i].clear();
for(i=0;i<n;++i)
scanf("%d %d %d",&dolls[i].x,&dolls[i].y,&dolls[i].z);
for(i=0;i<n;++i)
{
for(j=0;j<n;++j)
if((dolls[i].x<dolls[j].x)&&(dolls[i].y<dolls[j].y)
&&(dolls[i].z<dolls[j].z))
map[i].push_back(j);
}
for(i=0;i<n;++i)
{
memset(used,0,sizeof(used));
if(match(i))
ans++;
}
printf("%d\n",n-ans);
}
return 0;
}