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. python切片练习

    这块儿没什么难的,细心一点就好 L = [] n = 1 while n <= 99: L.append(n) n = n + 2 print(L) #但是在Python中,代码不是越多越好,而 ...

  2. OD调试篇1—Hello

    OD调试篇1—Hello 要求:通过OD将程序的标题“I love fishc.com”改为“I love you” 一.找到程序的标题“I love fishc.com” 1.把程序拖到OD运行出现 ...

  3. python命令行解析工具argparse模块【5】

            上一节我们学习了parse_args()的用法,这一节,我们将继续学习argparse的其他一些用法.         1.sub-commands子命令         argpar ...

  4. hdoj 2222

    http://acm.hdu.edu.cn/showproblem.php?pid=2222 第一道 AC自动机.....trie树的建立 和 AC自动机的查询,,可作模版... 解题思路:AC的应用 ...

  5. zepto API参考(~~比较全面)

    Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jquery有着类似的api. 如果你会用jquery,那么你也会用zepto. 设计的目的是提供jquery的类似的APIs ...

  6. 这些屌炸天的创业者为何对投资人说NO

    曾有人说,世上的创业者只分为两种,一种是找到投资的,一种是没有找到的. 但其实还有第三种,就是那些拒绝了投资人的创业者. 他们摒弃了投资人抛来的橄榄枝,并非不差钱,不接受投资的原因大体出于两个方面,一 ...

  7. 告别IE给我们的web开发带来的困扰(使用chrome frame v8引擎)

    茶爸爸个人微信:benyzhous,公众号:cha-baba欢迎骚扰 由于客户所有机器必须使用IE6浏览器,导致我们在开发项目过程中遇到非常多的样式与性能问题,在偶然的一次使用360软件管家搜索chr ...

  8. Android 5.0五大安全特性

    全盘加密(Full Disk Encryption, FDE) 对所有闪存数据加密.性能下降较大 Nexus 6,Nexus 9无法关闭FDE 对于其它设备.Google推荐开启 多用户支持 4.2中 ...

  9. 一、cocos2dx之如何优化内存使用(高级篇)

    本文由qinning199原创,转载请注明:http://www.cocos2dx.net/?p=93 一.内存优化原则 为了优化应用内存,你应该知道是什么消耗了你应用的大部分内存,答案就是Textu ...

  10. VS插件开发——格式化变量定义语句块

    插件介绍 代码地址:https://github.com/sun2043430/vs2008_format_variable_define_plugin/ 在vs里,对选中的变量定义块进行格式化,效果 ...