Dolls

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

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个布娃娃,可以用长宽高代表他们的特征,如果一个布娃娃的长宽高都比另一个小,那么这个布娃娃可以放到另一个的里面,问你求把布娃娃放置到另一个里,剩下的最少娃娃数量

 
思路: 最小路径覆盖=顶点数-最大匹配数
import java.io.*;
import java.util.*;
public class Main {
int n,MAX=10010;
int[][] map;
int[] link=new int[MAX];
boolean[] mark=new boolean[MAX];
public static void main(String[] args) {
new Main().work();
} void work(){
Scanner sc=new Scanner(new BufferedInputStream(System.in));
while(sc.hasNext()){
n=sc.nextInt();
if(n==0) break;
Node node[]=new Node[n];
for(int i=0;i<n;i++){
int wi=sc.nextInt();
int li=sc.nextInt();
int hi=sc.nextInt();
node[i]=new Node(wi,li,hi);
}
Arrays.sort(node);
map=new int[500][508];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(node[i].wi<node[j].wi&&node[i].li<node[j].li&&node[i].hi<node[j].hi){
map[i][j]=1;
}
}
}
hungary();
}
} void hungary(){
int ans=0;
Arrays.fill(link, 0);
for(int i=0;i<n;i++){
Arrays.fill(mark, false);
if(DFS(i))
ans++;
}
System.out.println(n-ans);
} boolean DFS(int x){
for(int i=0;i<n;i++){
if(map[x][i]==1&&!mark[i]){
mark[i]=true;
if(link[i]==0||DFS(link[i])){
link[i]=x;
return true;
}
}
}
return false;
} class Node implements Comparable<Node>{
int wi;
int li;
int hi;
Node(int wi,int li,int hi){
this.wi=wi;
this.li=li;
this.hi=hi;
}
public int compareTo(Node o) {
if(this.wi>o.wi) return 1;
if((this.wi==o.wi)&&(this.li>o.li)) return 1;
if((this.wi==o.wi)&&(this.li==o.li)&&(this.hi>o.hi))
return 1;
return -1;
}
}
}

HDU 4160 Dolls (最小路径覆盖=顶点数-最大匹配数)的更多相关文章

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

    先找出强连通分量缩点,然后就是最小路径覆盖. 构造一个二分图,把每个点\(i\)拆成两个点\(X_i,Y_i\). 对于原图中的边\(u \to v\),在二分图添加一条边\(X_u \to Y_v\ ...

  2. hdu 1151 Air Raid(二分图最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K To ...

  3. HDU 3861 The King’s Problem (强连通缩点+DAG最小路径覆盖)

    <题目链接> 题目大意: 一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.所有点只能属于一块区域:2,如果两点相互可达,则这两点必然要属于同一区域:3,区域内任意两点 ...

  4. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

    http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  5. POJ 3020 Antenna Placement(无向二分图的最小路径覆盖)

    ( ̄▽ ̄)" //无向二分图的最小路径覆盖数=顶点总数-最大匹配数/2(最大匹配数=最小点覆盖数) //这里最大匹配数需要除以2,因为每两个相邻的*连一条边,即<u,v>和< ...

  6. ●hihocoder #1394 网络流四·最小路径覆盖

    题链: http://hihocoder.com/problemset/problem/1394 题解: 有向图最小路径覆盖:最少的路径条数不重不漏的覆盖所有点. 注意到在任意一个最小路径覆盖的方案下 ...

  7. HDU 3861 The King’s Problem 最小路径覆盖(强连通分量缩点+二分图最大匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 最小路径覆盖的一篇博客:https://blog.csdn.net/qq_39627843/ar ...

  8. (匹配 最小路径覆盖)Air Raid --hdu --1151

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1151 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 3861 The King's Problem(强连通分量缩点+最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=3861 题意: 国王要对n个城市进行规划,将这些城市分成若干个城市,强连通的城市必须处于一个州,另外一个州内的任意 ...

随机推荐

  1. DevExpress ASP.NET 使用经验谈(7)-ASPxTreeList控件使用

    这一节,将介绍ASPxTreeList控件的使用,首先,我们增加一个标准地址库表AddressGB, 建表语句如下: CREATE TABLE [dbo].[AddressGB]( [Code] [v ...

  2. UIScrollView的几个要点总结

    从你的手指touch屏幕开始,scrollView开始一个timer,如果: 1.  150ms内如果你的手指没有任何动作,消息就会传给subView. 2.  150ms内手指有明显的滑动(一个sw ...

  3. 电信光纤猫 f412超级密码

    中兴F412光猫超级密码破解.破解用户限制.关闭远程控制.恢复路由器拨号 http://bbs.mydigit.cn/simple/?t1021161.html 不少家庭都改了光纤入户,那肯定少不了光 ...

  4. Sed简介 (转)

    Sed简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓 ...

  5. Vmware虚拟机网络模式及虚拟机与物理机通信方法

    [转]http://www.cqeis.com/news_detail/newsId=1477.html Vmware虚拟机软件是一个“虚拟PC”软件,它使你可以在一台机器上同时运行二个或更多Wind ...

  6. c语言中双维数组与指针的那点事儿

    说起c语言的指针,估计对c语言只是一知半解的同志们可能都会很头疼,尤其它跟数组又无耻的联系到一起的时候,就更加淫荡了!!! 怎么说呢,就是有一点规定:(或准则) 数组名可以看成是指向数组头元素的指针, ...

  7. (IOS)签名Demo

    思路是将每一次按下屏幕的touch move时的点存到一个数组里,即一个数组相当于一个笔画:再将该代表笔画的数组保存到一个大数组中,每组每次touch的移动都历遍大数组和笔画数组,将点于点之间连接起来 ...

  8. boost库学习随记六:使用同步定时器、异步定时器、bind、成员函数回调处理、多线程的同步处理示例等

    一.使用同步定时器 这个示例程序通过展示如何在一个定时器执行一个阻塞等待. //makefile #-------------------------------------------------- ...

  9. 解题报告 HDU1087 Super Jumping! Jumping! Jumping!

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  10. 工商管理硕士(MBA)-北大国际MBA

    工商管理硕士(MBA)-北大国际MBA [EMBA校友跨届晚会]不管风雨彩虹 我们永远在一起