您的位置:首页 > 其它

HDU 4160 Dolls 最小路径覆盖

2015-05-22 20:23 399 查看


Dolls

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1240 Accepted Submission(s): 593



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

二分图最小路径覆盖=点数-最大匹配

/** Author: ☆·aosaki(*’(OO)’*)  niconiconi★ **/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <stack>
//#include <tuple>
#define ALL(v) (v).begin(),(v).end()
#define foreach(i,v) for (__typeof((v).begin())i=(v).begin();i!=(v).end();i++)
#define SIZE(v) ((int)(v).size())
#define mem(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define lowbit(x) (x&(-x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define PI acos(-1.0)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define TT cout<<"*****"<<endl;
#define TTT cout<<"********"<<endl;
inline int gcd(int a,int b)
{
return a==0?b:gcd(b%a,a);
}

#define INF 1e9
#define eps 1e-8
#define mod 10007
#define MAX 10010

using namespace std;
const int maxn=501;
int uN,vN;
int g[maxn][maxn];
int linker[maxn];
bool used[maxn];

struct aoi
{
int a,b,c;
}b[501];

bool dfs(int u)
{
int v;
for(v=0;v<vN;v++)
if(g[u][v]&&!used[v])
{
used[v]=1;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return 1;
}
}
return false;
}

int hungary()
{
int re=0;
int u;
mem1(linker);
for(u=0;u<uN;u++)
{
mem(used);
if(dfs(u))  re++;
}
return re;
}

int main()
{
//freopen("in.txt","r",stdin);
int n,ji=0;
while(sc(n),n)
{
mem(g);
uN=n;
vN=n;
lp(i,n)
{
sc(b[i].a);
sc(b[i].b);
sc(b[i].c);
}
lp(i,n)
lp(j,n)
{
if(b[i].a>b[j].a && b[i].b>b[j].b && b[i].c>b[j].c)
g[i-1][j-1]=1;
}
printf("%d\n",n-hungary());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: