HDU 4160 Dolls(二分图匹配+匈牙利算法+最小路径覆盖)
来源:互联网 发布:手机视频点播软件 编辑:程序博客网 时间:2024/06/05 22:47
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.
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.
35 4 827 10 10100 32 52331 2 12 1 11 1 241 1 12 3 23 2 24 4 40
132
题解:
题意:
给一堆娃娃和娃娃的长宽高,如果一个娃娃长宽高都小于另一个娃娃的,就可以套上去,问最少剩下多少娃娃
思路:
匈牙利算法模板题,看到数据比较小直接邻接矩阵搞的,花了200ms,看到别人用预处理一遍+邻接表搞的60ms。。看来以后有必要优化一下算法了
还有就是:最小路径覆盖=顶点数-最大匹配数
代码:
#include<algorithm>#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<deque>#define M (t[k].l+t[k].r)/2#define lson k*2#define rson k*2+1#define ll long longusing namespace std;struct node{ int len,wid,h;}doll[505];//存娃娃情况int vis[505];int used[505];//存套在里面的娃娃int n;int find(int u)//匈牙利算法{ int i; for(i=1;i<=n;i++) { if(!vis[i]&&doll[i].len<doll[u].len&&doll[i].h<doll[u].h&&doll[i].wid<doll[u].wid)//没被选并且符合条件 { vis[i]=1; if(!used[i]||find(used[i]))//如果没被套或者可以选过一个被套 { used[i]=u; return 1; } } } return 0;}int main(){ int i,j,k,ans; while(scanf("%d",&n)!=EOF&&n) { for(i=1;i<=n;i++) { used[i]=0; scanf("%d%d%d",&doll[i].len,&doll[i].wid,&doll[i].h); } ans=0; for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",n-ans);//最小路径覆盖=顶点数-最大匹配数 } return 0;}
阅读全文
0 0
- HDU 4160 Dolls(二分图匹配+匈牙利算法+最小路径覆盖)
- hdu 4160 Dolls【最小路径覆盖----二分匹配】
- hdu 4160 Dolls 二分图最小路径覆盖
- HDOJ 题目4160Dolls(二分图,最小路径覆盖)
- HDU 2063 过山车(匈牙利算法 二分图的最小顶点覆盖 二分图最大匹配)
- POJ 1422 Air Raid(二分图匹配+最小路径覆盖+匈牙利算法)
- 彻底搞定二分图的匈牙利算法,最大匹配数(最小覆盖数)、最大独立数、最小路径覆盖
- hdu 4160 Dolls--最小点集覆盖=V-二分图最大匹配
- HDU 1151 Air Raid(匈牙利算法 二分图的最小路径覆盖 )
- HDU 4160 Dolls (最小路径覆盖=顶点数-最大匹配数)
- hdu 4160 Dolls (最小路径覆盖)
- [hdu 4160] Dolls(最小路径覆盖)
- 【HDU】4160 Dolls 最小路径覆盖
- HDU 4160 Dolls(DAG最小路径覆盖)
- HDU 4160 Dolls 最小路径覆盖
- HDU 4160 — Dolls 最小路径覆盖
- HDU 4160 Dolls(DAG最小路径覆盖)
- HDU 4160 Dolls(DAG最小路径覆盖)
- Ubuntu15中安装redis以及redis的简单配置
- 浅谈歌词解析
- socket套接字编程预备知识
- Java中的自定义异常
- 如何在Idea导入myeclipse项目
- HDU 4160 Dolls(二分图匹配+匈牙利算法+最小路径覆盖)
- PTA 5-52 两个有序链表序列的交集 (20分) (单链表)
- String数组 未初始化 为null
- git 源码下载
- 微信网页授权登录
- 线程重用——线程池的基本原理
- leetcode--Path Sum
- 输入并逐行输出
- android相关错误