HDU 4160 二分图最小点覆盖
来源:互联网 发布:windows system是什么 编辑:程序博客网 时间:2024/05/14 04:42
比赛的时候做道题一直用Dp做,一直wr,,,一直wr了十几次最后还是没有过。。。。。。。。。。。。。最后才知道原来是二分图最小点集覆盖,完全想错了。。。。。。。。。。。崩溃!
建图很容易,就是如果一个玩具能放到另一个玩具里面,则这两个玩具之间建边。之后求二分图最小点集覆盖就可以了。
题目让求最后最少剩下多少个玩具,即为最少用多少个玩具把这些玩具全部覆盖。题目:
Dolls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 106 Accepted Submission(s): 49
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.
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
35 4 827 10 10100 32 52331 2 12 1 11 1 241 1 12 3 23 2 24 4 40
Sample Output
132
#include <iostream>#include <algorithm>#include <cstdio>#include <string.h>#include <vector>using namespace std;struct matrix{ int len,wid,height;}aa[510];int flag[510],visted[510];vector<int> map[510];bool dfs(int x){ //visted[x]=1; for(int i=0;i<map[x].size();++i){ int j=map[x][i]; if(!visted[j]){ visted[j]=1; if(flag[j]==-1||dfs(flag[j])){ flag[j]=x; return true; } } } return false;}int main(){ //freopen("1.txt","r",stdin); int n; while(scanf("%d",&n)&&n){ memset(map,0,sizeof(map)); memset(flag,-1,sizeof(flag)); for(int i=1;i<=n;++i) scanf("%d%d%d",&aa[i].wid,&aa[i].len,&aa[i].height); for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j){ if(aa[i].wid<aa[j].wid&&aa[i].len<aa[j].len&&aa[i].height<aa[j].height) map[i].push_back(j); } } int count=0; for(int i=1;i<=n;++i){ memset(visted,0,sizeof(visted)); if(dfs(i)) count++; } printf("%d\n",n-count); } return 0;}
- HDU 4160 二分图最小点覆盖
- hdu 1150 二分图 最小点覆盖=最大匹配
- HDU 2119 Matrix【二分图之最小点集覆盖】
- HDU 1150 二分图匹配 最小点覆盖
- hdu 1498 二分图—最小点覆盖
- HDU 1150 二分图匹配 最小点覆盖
- HDU-1150 HK二分图最小点覆盖
- Machine Schedule hdu 1150 二分图的最小点覆盖
- hdu 2119 Matrix 二分图 最小点覆盖
- hdu 2119 二分图匹配之最小点集覆盖
- hdu 1281 棋盘游戏(二分图匹配--最小点覆盖)
- hdu 3360 National Treasures(二分图匹配--最小点覆盖)
- hdu 1150 二分图最大匹配最小点覆盖
- HDU 1150 Machine Schedule 二分图最小覆盖点
- HDU 1150 Machine Schedule 二分图最小覆盖点
- HDU 2119 Matrix 二分图最小点覆盖
- HDU 1054 Strategic Game 二分图最小点覆盖
- HDU 1150 二分图最小点集覆盖
- Android学习:SeekBar实现音量调节
- 导入证书_WS应用_Server
- iframe 背景透明
- 下载服务器文件
- C++:成员函数的重载、覆盖与隐藏
- HDU 4160 二分图最小点覆盖
- 算法导论读书笔记一 算法分析
- PDF转换成图片
- SQL PLUS 更改行宽
- C语言中strcpy,strcmp,strlen,strcat函数原型
- ASP.NET中实现伪静态路由
- HDOJ 2955 Robberies (01背包)
- 冒泡法排序(从小到大)
- quagga线程机制概述