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. 1
  2. 3
  3. 2
  1.  

题意:有n个布娃娃,可以用长宽高代表他们的特征,如果一个布娃娃的长宽高都比另一个小,那么这个布娃娃可以放到另一个的里面,问你求把布娃娃放置到另一个里,剩下的最少娃娃数量

  1.  
  1. 思路: 最小路径覆盖=顶点数-最大匹配数
  1. import java.io.*;
  2. import java.util.*;
  3. public class Main {
  4. int n,MAX=10010;
  5. int[][] map;
  6. int[] link=new int[MAX];
  7. boolean[] mark=new boolean[MAX];
  8. public static void main(String[] args) {
  9. new Main().work();
  10. }
  11.  
  12. void work(){
  13. Scanner sc=new Scanner(new BufferedInputStream(System.in));
  14. while(sc.hasNext()){
  15. n=sc.nextInt();
  16. if(n==0) break;
  17. Node node[]=new Node[n];
  18. for(int i=0;i<n;i++){
  19. int wi=sc.nextInt();
  20. int li=sc.nextInt();
  21. int hi=sc.nextInt();
  22. node[i]=new Node(wi,li,hi);
  23. }
  24. Arrays.sort(node);
  25. map=new int[500][508];
  26. for(int i=0;i<n;i++){
  27. for(int j=0;j<n;j++){
  28. if(node[i].wi<node[j].wi&&node[i].li<node[j].li&&node[i].hi<node[j].hi){
  29. map[i][j]=1;
  30. }
  31. }
  32. }
  33. hungary();
  34. }
  35. }
  36.  
  37. void hungary(){
  38. int ans=0;
  39. Arrays.fill(link, 0);
  40. for(int i=0;i<n;i++){
  41. Arrays.fill(mark, false);
  42. if(DFS(i))
  43. ans++;
  44. }
  45. System.out.println(n-ans);
  46. }
  47.  
  48. boolean DFS(int x){
  49. for(int i=0;i<n;i++){
  50. if(map[x][i]==1&&!mark[i]){
  51. mark[i]=true;
  52. if(link[i]==0||DFS(link[i])){
  53. link[i]=x;
  54. return true;
  55. }
  56. }
  57. }
  58. return false;
  59. }
  60.  
  61. class Node implements Comparable<Node>{
  62. int wi;
  63. int li;
  64. int hi;
  65. Node(int wi,int li,int hi){
  66. this.wi=wi;
  67. this.li=li;
  68. this.hi=hi;
  69. }
  70. public int compareTo(Node o) {
  71. if(this.wi>o.wi) return 1;
  72. if((this.wi==o.wi)&&(this.li>o.li)) return 1;
  73. if((this.wi==o.wi)&&(this.li==o.li)&&(this.hi>o.hi))
  74. return 1;
  75. return -1;
  76. }
  77. }
  78. }

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. ASP.NET 操作配置文件

    1.配置文件的各种操作 http://www.cnblogs.com/shimeng3344518/archive/2007/04/23/723999.html 2. http://www.jb51. ...

  2. centos5.5 安装git

    查看centos版本 # cat /etc/redhat-release CentOS release 5.5 (Final) 安装git 下载: 如果有老版本的git: #git clone git ...

  3. Unqualified name lookup

    Unqualified name lookup File scope Namespace scope For an qualified name, that is a name that does n ...

  4. poj2774之最长公共子串

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 18794   Accepted: 77 ...

  5. php随笔8-thinkphp OA系统 客户管理

    Action: CustomerinfosAction.class.php <?php /* * 客户信息 控制器 * @author lifu <504861378@qq.com> ...

  6. C语言回溯算法解决N皇后问题

    回溯算法的模型是 x++, not satisfy ? x-- : continue. 代码中x作列号,y[x]保存第x列上皇后放置的位置. #include<stdio.h> #incl ...

  7. linux基础随笔

    磁盘管理 sda s:磁盘接口的类型(sata scsci sas) d:驱动器(drive) a:(第一块磁盘,同理b第二块磁盘)hda h:ide接口 第一块磁盘的第一个分区:sda1 mount ...

  8. extjs 优化小建议

    1 原文信息 原文标题: Sencha Con 2013: Ext JS Performance tips 原文地址: [http://edspencer.net/2013/07/19/sencha- ...

  9. C#学习之-----再论委托

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  10. Python 第十一篇:开发堡垒机

    一:SqlAlchemy ORM ORM:Object Relational Mapping 对象关系映射是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 SQLAlchemy是 ...