hdu4160 Dolls

news/2024/11/24 8:49:33/

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;
}

http://www.ppmy.cn/news/325668.html

相关文章

hdoj 4160 Dolls

http://acm.hdu.edu.cn/showproblem.php?pid4160 转化为二分图的最小路径覆盖问题。 那么答案就是n-最大匹配数 View Code #include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> #include<vector> #define maxn 1000…

BZOJ4160 [Neerc2009]Exclusive Access 2 题解(Dilworth定理+状压DP)

题目&#xff1a;BZOJ4160. 题目大意&#xff1a;给定一张 n n n个点 m m m条边无向图&#xff0c;要求给每条边定向&#xff0c;求定向后有向图上的最长路最短是多少. 1 ≤ n ≤ 15 , 1 ≤ m ≤ 100 1\leq n\leq 15,1\leq m\leq 100 1≤n≤15,1≤m≤100. 首先&#xff0c;最…

hdu4160

/* 分析&#xff1a; 哎呀&#xff0c;在用C提交ac的里面竟然排第一呀&#xff0c;so~吃惊呀~ 最小路径覆盖&#xff0c;如果i可以放到j里面&#xff0c;那么就构建一条 i到j的有向边。 2012-07-14 */ #include"stdio.h" #include"string.h"struct A {int …

HDU 4160 最小路径覆盖

题意: 有N个木偶,木偶有3项指标,w,i,h. 如果第i个木偶的3项指标对应小于第j个木偶的3项指标,那么i木偶可以放到j木偶中. 且一个木偶里面只能直接的放一个别的木偶.问你这N个木偶最优嵌套的方案下,最多有几个木偶不能被任何木偶嵌套? 分析: 如果i木偶能放在j木偶中,那么连一条…

oracle19c无法分配共享内存,无法分配 4160 字节的共享内存,求救!!

select count(*) from dba_objects where statusINVALID and owner in (SYS,SYSTEM); 为0 我的建库步骤&#xff1a; connect SYS/change_on_install as SYSDBA set echo on spool /oracle/app/oracle/admin/fjdc/create/CreateDB.log startup nomount pfile"/oracle/app/…

USB隔离市场,光耦产品过时了?光耦 or磁耦:即数字隔离芯片ADuM4160

USB隔离市场&#xff0c;光耦产品过时了&#xff1f; 2009-05-24来源: EEWORLD 汤宏琳 收藏评论0 “最近我们在北京做了一个参考平台&#xff0c;但在与笔记本连接时&#xff0c;很多接口速度却不够&#xff0c;”ADI亚太区医疗事业资深业务经理周文胜不无感慨地告诉EEWORLD。…

USB实现隔离的四种方法分析-方法四最好: 数字隔离器 USB隔离芯片ADuM3160、ADuM4160

USB实现隔离的四种方法分析 目前在办公室和家庭中使用的标准信息处理设备—个人电脑 &#xff08;PC&#xff09;&#xff0c;使用通用串行总线&#xff08;U S B&#xff09; 与大多数外设进行通讯。标准化、低成本 及软件和开发工具的支持已使个人电脑成为医疗和工业应用很具…

ORA-04031: 无法分配4160字节的共享内存 (large pool,unknown object,hash-join subh

ORA-04031: 无法分配4160字节的共享内存 ("large pool"&#xff0c;"unknown object"&#xff0c;"hash-join subh"&#xff0c;"kllcqc:kllcqslt") 解决方法&#xff1a; SQL> show parameter dispa NAME …