HDU 4160 最小路径覆盖

Dolls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1040    Accepted Submission(s): 496

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

题目意思:
有n个箱子,每个箱子长宽高分别为l,w,h。若l[i]<l[j]&&w[i]<w[j]&&h[i]<h[j],那么箱子 i 可以放到箱子 j 里面,经过一些操作使一些箱子放进另外一些箱子中,求最终漏在外面的箱子个数最小多少。

思路:

把包含的箱子弄到一个集合,把被包含的箱子弄到另外一个集合,二分最大匹配是最佳方案,设最大二分匹配为num,由于每有一个匹配,漏在外面的箱子数-1,那么最终答案为n-num。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <iostream>
 6 using namespace std;
 7 #define N 550
 8
 9 vector<int>ve[N];
10 int from[N];
11 int visited[N];
12 int n;
13
14 struct node{
15     int w, l, h;
16 }a[N];
17
18 int mark(int u){
19     int i, v;
20     for(i=0;i<ve[u].size();i++){
21         v=ve[u][i];
22         if(!visited[v]){
23             visited[v]=1;
24             if(from[v]==-1||mark(from[v])){
25                 from[v]=u;
26                 return 1;
27             }
28         }
29     }
30     return 0;
31 }
32 main()
33 {
34     int i, j, k, num;
35     while(scanf("%d",&n)==1&&n){
36         memset(from,-1,sizeof(from));
37         for(i=1;i<=n;i++){
38             ve[i].clear();
39             scanf("%d %d %d",&a[i].w,&a[i].l,&a[i].h);
40         }
41         for(i=1;i<=n;i++){
42             for(j=1;j<=n;j++){
43                 if(a[j].l>a[i].l&&a[j].w>a[i].w&&a[j].h>a[i].h){
44                     ve[j].push_back(i);
45                 }
46             }
47         }
48         num=0;
49         for(i=1;i<=n;i++){
50             memset(visited,0,sizeof(visited));
51             if(mark(i))
52             num++;
53         }
54         printf("%d\n",n-num);
55     }
56 }

HDU 4160 最小路径覆盖,布布扣,bubuko.com

时间: 2024-10-18 03:27:54

HDU 4160 最小路径覆盖的相关文章

HDU 1350 最小路径覆盖

Taxi Cab Scheme Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 707    Accepted Submission(s): 336 Problem Description Running a taxi station is not all that simple. Apart from the obvious dem

hdu1151 最小路径覆盖

http://acm.hdu.edu.cn/showproblem.php?pid=1151 Problem Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town'

hdu 3861 The King’s Problem (强连通+最小路径覆盖)

The King's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1637    Accepted Submission(s): 600 Problem Description In the Kingdom of Silence, the king has a new problem. There are N cit

HDU 1151 Air Raid(最小路径覆盖 = 顶点数 - 最大匹配数)

Air Raid Problem Description Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's streets you can never reach the same

HDU 3861.The King’s Problem 强联通分量+最小路径覆盖

The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2947    Accepted Submission(s): 1049 Problem Description In the Kingdom of Silence, the king has a new problem. There are N cit

HDU 3861 The King’s Problem(强连通+二分图最小路径覆盖)

HDU 3861 The King's Problem 题目链接 题意:给定一个有向图,求最少划分成几个部分满足下面条件 互相可达的点必须分到一个集合 一个对点(u, v)必须至少有u可达v或者v可达u 一个点只能分到一个集合 思路:先强连通缩点,然后二分图匹配求最小路径覆盖 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> #include <

hdu 1151 Air Raid (最小路径覆盖)

Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3085    Accepted Submission(s): 2004 Problem Description Consider a town where all the streets are one-way and each street leads from on

HDU 3861 The King&#39;s Problem(强连通分量缩点+最小路径覆盖)

http://acm.hdu.edu.cn/showproblem.php?pid=3861 题意: 国王要对n个城市进行规划,将这些城市分成若干个城市,强连通的城市必须处于一个州,另外一个州内的任意两个城市u,v,有从u到v的路径或从v到u的路径.求最少可以分成几个州. 思路: 这道题目挺好. 首先,强连通分量进行缩点,重新建图. 新建的图就是一个DAG图,接下来就转换成了最小路径覆盖问题. 最小路径覆盖就是用尽量少的不相交的简单路径覆盖DAG的所有顶点.每个顶点只属于一条路径,单个顶点也可以

最小路径覆盖 hdu 1151 hdu 3335

Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3122    Accepted Submission(s): 2027 Problem Description Consider a town where all the streets are one-way and each street leads from on