http://www.elijahqi.win/2017/12/31/hdu4160-dolls/ ‎

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

Source
The 2011 Syrian Collegiate Programming Contest
最小路径覆盖问题
从源向每个节点的出点建边权为1的边 (因为只能做一回出点和入点)然后每个节点的的入点向汇建容量为1边 如果一个娃娃能覆盖另一个则从出点向入点建容量为1的边 然后跑dinic 即求出了最大匹配 初始的时候我认为我所有娃娃都得摆在外面 如果可以嵌套就就证明 这两个我可以变成一个
一个匹配我可以把两个点之间用一条边覆盖 就给连起来了 所以最后用总节点数-最大匹配即可

#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1100
#define inf 0x3f3f3f3f
using namespace std;
inline char gc(){static char now[1<<16],*S,*T;if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}return *S++;
}
inline int read(){int x=0;char ch=gc();while(ch<'0'||ch>'9') ch=gc();while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}return x;
}
struct node{int x,y,z,next;
}data[N*N*3];
int num=1,h[N],w[N],l[N],level[N],hh[N],T,n;
inline void insert1(int x,int y,int z){data[++num].y=y;data[num].z=z;data[num].next=h[x];h[x]=num;data[num].x=x;data[++num].y=x;data[num].z=0;data[num].next=h[y];h[y]=num;data[num].x=y;
}
inline bool bfs(){queue<int>q;memset(level,0,sizeof(level));level[0]=1;q.push(0);while(!q.empty()){int x=q.front();q.pop();for (int i=h[x];i;i=data[i].next){int y=data[i].y,z=data[i].z;if (level[y]||!z) continue;level[y]=level[x]+1;q.push(y);if (y==T) return 1;}}return 0;
}
inline int dfs(int x,int s){if (x==T) return s;int ss=s;for (int i=h[x];i;i=data[i].next){int y=data[i].y,z=data[i].z;if (level[x]+1==level[y]&&z){int xx=dfs(y,min(z,s));if (!xx) level[y]=0;s-=xx;data[i].z-=xx;data[i^1].z+=xx;if (!s) return ss;}}return ss-s;
}
int main(){freopen("hdu4160.in","r",stdin);while(1){n=read();if (!n) return 0;num=1;memset(h,0,sizeof(h));T=2*n+1;for (int i=1;i<=n;++i) l[i]=read(),w[i]=read(),hh[i]=read();for (int i=1;i<=n;++i) insert1(0,i,1),insert1(i+n,T,1);for (int i=1;i<=n;++i){for (int j=1;j<=n;++j){if (i==j) continue;if (l[i]<=l[j]||w[i]<=w[j]||hh[i]<=hh[j]) continue;insert1(i,j+n,1);}}int ans=0;//  for (int i=2;i<=num;++i) printf("%d %d %d\n",data[i].x,data[i].y,data[i].z);while(bfs()) ans+=dfs(0,inf);//for (int i=2;i<=num;++i) printf("%d %d %d\n",data[i].x,data[i].y,data[i].z);printf("%d\n",n-ans);}return 0;
}

hdu4160 Dolls相关推荐

  1. hdu 4160 Dolls 匈牙利算法求最大匹配

    Dolls                                                                               Time Limit: 2000 ...

  2. hdu 1677 Nested Dolls 子串

    题目: A - Nested Dolls Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  3. Russian Dolls on the Christmas Tree

    题目链接:Russian Dolls on the Christmas Tree 显然可以dfs序转区间之后上莫队,不过感觉会被卡. 其实也可以dfs序之后,对询问区间排序,然后线段树. 我懒得dfs ...

  4. HDU4160(最小路径覆盖问题)

    题意:当满足条件wi<wj,hi<hl和li<lj时,求解通过优化嵌套给定的娃娃可以获得的最外层洋娃娃的最小数量. 思路:如果嵌套的娃娃越多,则剩下的娃娃就越少,意味着单独出来的娃娃 ...

  5. 中石油训练赛 - Russian Dolls on the Christmas Tree(树上启发式合并/主席树)

    题目链接:点击查看 题目大意:给出一棵 n 个节点的树,以点 1 为根,现在对于每个节点作为根的子树求解:子树中有多少个编号不相交的连续子段,如:1 2 4 5 7,共有三个连续的段,分别为 [ 1 ...

  6. hdu 4160 Dolls (最大独立)

    点击打开链接 需要排下序.. #include"stdio.h" #include"string.h" #include"stdlib.h" ...

  7. 2019 CCPC Final K - Russian Dolls on the Christmas Tree

    ~模板题qwq 题意:在一棵树中,假如某些节点的序号值是相连的,则可以把他们连接在一起,然后问你每一棵子树中的所有节点(包括当前节点)经过连接之后最后能剩余几段. 思路:很明显是一个树上启发式合并的模 ...

  8. HDU 1277 Nested Dolls

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1677 题意: 玩俄罗斯套娃,问最后至少还剩几个. 题解: 这题可以和拦截导弹做对比,因为这里是二维的 ...

  9. Russian Dolls on the Christmas Tree(主席树)

    传送门 题意:给你一颗树,每个节点都有一个标号,问你将一个节点所有子节点及其本身的标号连接能形成几段. 题解:大多是用线段树合并写的,所以补一发主席树的做法.将树用dfs序hash下来后,对于每一个节 ...

最新文章

  1. 2020-09-18
  2. 鸿蒙os系统的iphonexr,iPhoneXS/XR终极防水测试:iPhoneXR不幸阵亡
  3. java中解密的思想_北大青鸟翔天解密,Java核心思想两大点
  4. lombok进行有参无参构造出现的问题
  5. 类型之间的相互转换php,php学习之数据类型之间的转换介绍
  6. C++ 面向对象 一
  7. (43)System Verilog 类中变量随机化
  8. 内核调试技巧-逆向寻踪,揭开 LACP 协议流程的神秘面纱
  9. SAP UI5 应用开发教程之六十一 - 在 SAP UI5 应用里绘制甘特图 Gantt Chart 试读版
  10. 沈阳大学专升本计算机宿舍,沈阳大学宿舍怎么样 住宿条件好不好
  11. 【C++STL库】stack常用函数学习
  12. 陆地生态系统生态学原理
  13. 甲基化芯片Beta值意义详解,以及minfi包使用
  14. 开源软件中的TOP10
  15. C# 进行 Starlink 仿真03:72轨道面 * 22颗卫星 F相位因子==11 的Walker星座,创建3168条星间链路,并与 icarus 论文的Python结果相对比。
  16. 十二、Hi3556移植RTL8189 WIFI驱动
  17. matlab线束,matlab中常用数学词汇.doc
  18. sqlserver数据批量插入
  19. Python 蜻蜓fm有声书批量下载 支持账号登录 原创源码
  20. 1-14 串口在S3C2440上的原理、配置与驱动实现

热门文章

  1. 防灾科技学院计算机好就业吗,防灾科技学院好就业吗?附防灾科技学院就业率最高的专业名单...
  2. mix2 android 公测,小米 6/MIX 2/Note 3 等正式停止 MIUI 12 开发版内测公测
  3. 51单片机四个并行I/O接口
  4. 2020年第二届“网鼎杯”网络安全大赛 白虎组 部分题目Writeup
  5. 给你的视频配音,只需这3款免费软件工具(文字转语音)!
  6. android魅族升级,魅族Android 4.4 Flyme升级教程教学详细介绍
  7. 浙江工业大学线下宣讲开始了,线上投递同步持续进行
  8. 100内质数算法,总是遇到这道题,有那么神奇吗
  9. 下料问题的列生成算法,matlab代码,简单易懂
  10. Android之使用GPS和NetWork定位