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. if和switch的区别,循环的for 和while的区别, 字符串常用的7种方法

    相同点: 都是用于多重选择 不同点: 多重IF没有switch选择结构的限制,特别适合变量处于某个连续区间的情况 switch只能处理等值条件判断的情况,而且条件必须是整型变量或者字符串变量 字符串的 ...

  2. LeetCode:链表排序

    Sort a linked list in O(n log n) time using constant space complexity. public class Solution { publi ...

  3. tf–idf算法解释及其python代码实现(上)

    tf–idf算法解释 tf–idf, 是term frequency–inverse document frequency的缩写,它通常用来衡量一个词对在一个语料库中对它所在的文档有多重要,常用在信息 ...

  4. MongoDB入门(1)--安装配置

    第一步:下载安装 首先当然是找到官方网站http://www.mongodb.org/ 进入下载页面 可以看到,当前最新版本是2.4.5,我的电脑是64位的win7,所以要下载第一个(说明一下,第二个 ...

  5. AOI自动光学检测机技术在电路板检查中的应用

    1.简述 AOI技术在许多不同的制造业领域使用,自从电子影像技术开始发展,就被各种人利用在不同的应用领域.大家最熟悉的数字相机.数字摄影机是大家生活中最常用到的器材之一,而工业产品的生产也大量使用这些 ...

  6. Qt 错误: 无法运行 release 下的可执行文件

        学习Qt有一点时间了,但之前都是在debug版本下进行编译运行,偶然切换到release版本下,却出现了如下错误: 错误提示:   This application failed to sta ...

  7. 【Java】:多线程下载

    import java.io.InputStream; import java.io.RandomAccessFile; import java.net.URL; import java.net.UR ...

  8. Putty远程登录VMware虚拟机Linux(Ubuntu12.04)

    为了不至于来回在Win7和Ubuntu12.04之间来回切换,在Win7下使用VMware9.0安装了Ubuntu12.04. 首先下载Vmware9.0虚拟机软件,下载地址为:VMware-work ...

  9. iOS-容易造成循环引用的三种场景

    ARC已经出来很久了,自动释放内存的确很方便,但是并非绝对安全绝对不会产生内存泄露.导致iOS对象无法按预期释放的一个无形杀手是——循环引 用.循环引用可以简单理解为A引用了B,而B又引用了A,双方都 ...

  10. 倒计时IE10+

    直接上代码,dome 里边有我做的列表倒计时(多个同时倒计时)下面是我做的例子,颜色可以自己设置的 <p name="daojishi" style="width: ...