博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hud4160 Dolls
阅读量:4572 次
发布时间:2019-06-08

本文共 2369 字,大约阅读时间需要 7 分钟。

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
二分图匹配
View Code
#include
#include
bool map[550][550],f[550];int t,g[550];struct node{ int x,y,z;}b[550];bool fun(int a){ int i; for(i=1;i<=t;i++) if(map[a][i]&&!f[i]) { f[i]=1; if(!g[i]||fun(g[i])) { g[i]=a; return 1; } } return 0;}int main(){ int i,j,num; while(scanf("%d",&t),t) { num=0; for(i=1;i<=t;i++) scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].z); memset(map,0,sizeof(map)); memset(g,0,sizeof(g)); for(i=1;i<=t;i++) for(j=1;j<=t;j++) if(b[i].x>b[j].x&&b[i].y>b[j].y&&b[i].z>b[j].z) map[i][j]=1; for(i=1;i<=t;i++) { memset(f,0,sizeof(f)); num+=fun(i); } printf("%d\n",t-num); } return 0;}

 

转载于:https://www.cnblogs.com/zlyblog/archive/2013/04/20/3033001.html

你可能感兴趣的文章
Maven多模块项目搭建
查看>>
Scala
查看>>
Android 中LinearLayout控件属性
查看>>
面向对象之多态性
查看>>
树状数组
查看>>
【2019.8.14 慈溪模拟赛 T1】我不是!我没有!别瞎说啊!(notme)(BFS+DP)
查看>>
多任务--进程 及 进程间通信
查看>>
多线程/多进程+QProgressBar实现进度条
查看>>
多任务(进程)案例----- 拷贝文件夹
查看>>
Kotlin的快速入门
查看>>
底层原理
查看>>
21. Merge Two Sorted Lists
查看>>
创建数组
查看>>
dict使用
查看>>
ASP.NET MVC的帮助类HtmlHelper和UrlHelper
查看>>
02_ListActive中响应事件 并LogCat输出
查看>>
doubleclick adx note
查看>>
Celery框架
查看>>
[c#]asp.net开发微信公众平台(4)关注事件、用户记录、回复文本消息
查看>>
[转载,感觉写的非常详细]DUBBO配置方式详解
查看>>