poj 1548
来源:互联网 发布:杨幂网络暴力事例 编辑:程序博客网 时间:2024/04/30 02:46
最小路径覆盖 = n - 最大匹配
能从a走到b,就连一条有向边
//tpl//ipqhjjybj_tpl.h//header.h#include <cstdio>#include <cstdlib>#include <map>#include <set>#include <algorithm>#include <cstring>#include <iostream>#include <vector>#include <string>#define mp(x,y) make_pair(x,y)#define pii pair<int,int>#define pLL pair<long long ,long long>#define rep(i,j,k) for(int i = j; i < k;i++)#define repn(i,j,k) for(int i = j; i <= k;i++)using namespace std;const int INF = 0x3f3f3f3f;const int N = 1300;int g[N][N];int cx[N],cy[N];int mark[N];int nx,ny;int dfs(int u) { rep(v,0,ny) { if(g[u][v]&&!mark[v])//u和v不要搞反了 { mark[v]=1; if(cy[v]==-1||dfs(cy[v])) { cx[u]=v; cy[v]=u; return 1; } } } return 0; } int maxmatch() { int res=0; memset(cx,-1,sizeof(cx)); memset(cy,-1,sizeof(cy)); rep(i,0,nx) { if(cx[i]==-1) { memset(mark,0,sizeof(mark)); res+=dfs(i); } } return res; } int x,y;map<pii,int> M;vector<pii >pm; int getNum(int x,int y){if(M.count(mp(x,y))){return M[mp(x,y)];}pm.push_back(mp(x,y));return M[mp(x,y)] = pm.size()-1;}int main(){while(scanf("%d %d",&x,&y)!=EOF){if(x==-1 && y == -1) break;M.clear() , pm.clear();memset(g,0,sizeof(g));int n ;getNum(x,y);while(scanf("%d %d",&x,&y)!=EOF){if(x==0 && y==0) break;getNum(x,y);}n = pm.size();rep(i,0,n){<span style="white-space:pre"></span>rep(j,0,n){<span style="white-space:pre"></span>if(i!=j)<span style="white-space:pre"></span>if(pm[i].first <=pm[j].first && pm[i].second <= pm[j].second){<span style="white-space:pre"></span>g[i][j] = 1;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}nx = ny = n;int ans = maxmatch();printf("%d\n",n-ans);}return 0;}
0 0
- poj 1548
- poj 1548
- Common Subsequence poj 1548
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ 1724 ROADS (搜索+剪枝)
- Android开发之日期、时间选择器(DatePicker和TimePicker)的功能和用法
- Pat(Advanced Level)Practice--1082(Read Number in Chinese)
- linux 进程前后台调度
- 集合(Map扩展)
- poj 1548
- HDU Today(prim——最小生成树)
- 集合(Collections-sort)-(Collections-max)-(Collections-binarySearch)
- JavaScript中的数组
- 路由器拆卸初体验
- Pat(Advanced Level)Practice--1083(List Grades)
- 3、ObjetARX应用程序基础
- hdu 1060 Leftmost Digit
- 安卓中的音频处理