POJ 2536 解题报告
来源:互联网 发布:美工要学哪些 编辑:程序博客网 时间:2024/06/07 04:44
这道题看着就是最大二分匹配的问题。用了之前POJ1274的代码就过了。
thestoryofsnow2536Accepted192K32MSC++2788B/* ID: thestor1 LANG: C++ TASK: poj1274 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;// See http://www.geeksforgeeks.org/maximum-bipartite-matching/ for more detailed explanationconst int MAXN = 200;const int MAXM = 200;// A DFS based recursive function that returns true if a// matching for vertex u is possiblebool DFS(int u, const bool adjMatrix[][MAXM], const int N, const int M, int match[], bool visited[]){// Try every job one by onefor (int v = 0; v < M; ++v){// If applicant u is interested in job v and v is// not visitedif (adjMatrix[u][v] && !visited[v]){// Mark v as visitedvisited[v] = true;// If job 'v' is not assigned to an applicant OR// previously assigned applicant for job v (which is match[v]) // has an alternate job available.// Since v is marked as visited in the above line, match[v] // in the following recursive call will not get job 'v' againif (match[v] < 0 || DFS(match[v], adjMatrix, N, M, match, visited)){match[v] = u;return true;}}}return false;}// Returns maximum number of matching from N to M// match: An array to keep track of the applicants assigned to jobs. // The value of match[i] is the applicant number// assigned to job i, the value -1 indicates nobody is assigned.int maximumBipartiteMatching(const bool adjMatrix[][MAXM], const int N, const int M, int match[], bool visited[]){// Count of jobs assigned to applicantsint mbm = 0;// Initially all jobs are availablememset(match, -1, M * sizeof(int));for (int u = 0; u < N; ++u){// Mark all jobs as not seen for next applicant.memset(visited, false, M * sizeof(bool));// Find if the applicant 'u' can get a jobif (DFS(u, adjMatrix, N, M, match, visited)){mbm++;}}return mbm;}int main(){int N, M;bool adjMatrix[MAXN][MAXM];int match[MAXM];bool visited[MAXM];while (scanf("%d%d", &N, &M) > 0){for (int i = 0; i < N; ++i){for (int j = 0; j < M; ++j){adjMatrix[i][j] = false;}}for (int u = 0; u < N; ++u){int si;scanf("%d", &si);for (int j = 0; j < si; ++j){int v;scanf("%d", &v);v--;adjMatrix[u][v] = true;}}// printf("[debug]adjMatrix:\n");// for (int u = 0; u < N; ++u)// {// printf("%d: ", u);// for (int v = 0; v < M; ++v)// {// printf("%d ", adjMatrix[u][v]);// }// printf("\n");// }int mbm = maximumBipartiteMatching(adjMatrix, N, M, match, visited);printf("%d\n", mbm);}return 0; }
0 0
- POJ 2536 解题报告
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1042 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- POJ 1001解题报告
- POJ 1002解题报告
- POJ 1006解题报告
- SDK API IDE专业术语解释
- 快速排序-quicksort
- 这么完美的梗,只有程序员才懂
- APP逆向(上)
- 深入Linux PAM体系结构
- POJ 2536 解题报告
- 4-5 链式表操作集 (20分)
- HDU 5731 2016多校Contest 1 F题【轮廓线DP+容斥原理】
- Basic access authentication
- Android模块功能系列(1)一底部Tab标签以及照相、相册弹窗效果
- 闭包
- android 中activity详细的启动模式
- 23种设计模式—UML图例
- ‘tools.jar’seems to be not in Studio classpath Please ensure JAVA_HOME points to JDK rather than JRE