2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want your help, is to determine what all of people can live in these planets.

题意:有N个人,每个人能适应若干个星球(共10个星球),每个星球能够容纳若干人,问是否能让所有人都有星球住。

其实应该是一个二分图多重匹配的题目。

不过一开始当成最大流的题目了,做的时候TLE了,然后将对10个星球的适应性的情况用状压变成了2^10种情况,即2^10种人,并且加上读入优化在vj上也卡过去了,不过在杭电上始终还是TLE了。

 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std; const int maxn=;
const int maxm=;
int match[maxn][maxm],g[maxn][maxm],cnt[maxm],lim[maxn],n,m;
bool vis[maxm]; bool dfs(int s){
for(int i=;i<m;++i){
if(g[s][i]==||vis[i]==)continue;
vis[i]=;
if(cnt[i]<lim[i]){
match[i][cnt[i]++]=s;
return ;
}
else{
for(int j=;j<lim[i];++j){
if(dfs(match[i][j])==){
match[i][j]=s;
return ;
}
}
}
}
return ;
}
bool hungary(int n){
for(int i=;i<n;++i){
memset(vis,,sizeof(vis));
if(dfs(i)==)return ;
}
return ;
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
memset(cnt,,sizeof(cnt));
for(int i=;i<n;++i)
for(int j=;j<m;++j)scanf("%d",&g[i][j]);
for(int i=;i<m;++i)scanf("%d",&lim[i]);
if(hungary(n))printf("YES\n");
else printf("NO\n");
}
return ;
}

多重匹配

 #pragma comment(linker,"/STACK:16777216")
#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxm=;
const int INF=0x3f3f3f3f; struct edge{
int from,to,c,f;
edge(int a,int b,int m,int n):from(a),to(b),c(m),f(n){}
}; struct dinic{
int s,t,m;
vector<edge>e;
vector<int>g[maxm];
bool vis[maxm];
int cur[maxm],d[maxm]; void init(int n){
for(int i=;i<=n;i++)g[i].clear();
e.clear();
} void add(int a,int b,int c){
e.push_back(edge(a,b,c,));
e.push_back(edge(b,a,,));
m=e.size();
g[a].push_back(m-);
g[b].push_back(m-);
} bool bfs(){
memset(vis,,sizeof(vis));
queue<int>q;
q.push(s);
vis[s]=;
d[s]=;
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<g[u].size();i++){
edge tmp=e[g[u][i]];
if(!vis[tmp.to]&&tmp.c>tmp.f){
d[tmp.to]=d[u]+;
vis[tmp.to]=;
q.push(tmp.to);
}
}
}
return vis[t];
} int dfs(int x,int a){
if(x==t||a==)return a;
int flow=,f;
for(int& i=cur[x];i<g[x].size();i++){
edge& tmp=e[g[x][i]];
if(d[tmp.to]==d[x]+&&(f=dfs(tmp.to,min(a,tmp.c-tmp.f)))>){
tmp.f+=f;
e[g[x][i]^].f-=f;
flow+=f;
a-=f;
if(a==)break;
}
}
if(!flow)d[x]=-;
return flow;
} int mf(int s,int t){
this->s=s;
this->t=t;
int flow=;
while(bfs()){
memset(cur,,sizeof(cur));
flow+=dfs(s,INF);
}
return flow;
}
}; int num[]; int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
memset(num,,sizeof(num));
dinic d;
d.init(m+(<<m)+);
int i,j;
for(i=;i<=n;i++){
int tmp=;
for(j=;j<=m;j++){
int a=;
char c=getchar();
while(c>''||c<'')c=getchar();
a=c-'';
tmp=tmp*+a;
}
num[tmp]++;
}
for(i=;i<=(<<m)-;i++){
if(num[i]){
d.add(,i,num[i]);
int tmp=i;
for(j=m;j>=;j--){
if(tmp&){
d.add(i,(<<m)+j,INF);
}
tmp>>=;
}
}
}
for(j=;j<=m;j++){
int a=;
char c=getchar();
while(c>''||c<'')c=getchar();
while(c>=''&&c<=''){
a=a*+c-'';
c=getchar();
}
d.add((<<m)+j,m+(<<m)+,a);
}
if(n==d.mf(,m+(<<m)+))printf("YES\n");
else printf("NO\n");
}
return ;
}

最大流

hdu3605 Escape 二分图多重匹配/最大流的更多相关文章

  1. HDU3605 Escape —— 二分图多重匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others)    ...

  2. POJ3189 Steady Cow Assignment —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-3189 Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65 ...

  3. POJ2112 Optimal Milking —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-2112 Optimal Milking Time Limit: 2000MS   Memory Limit: 30000K T ...

  4. POJ2289 Jamie's Contact Groups —— 二分图多重匹配/最大流 + 二分

    题目链接:https://vjudge.net/problem/POJ-2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 6 ...

  5. HDU - 3605 Escape (缩点+最大流/二分图多重匹配)

    题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...

  6. 【网络流24题】No.7 试题库问题 (最大流,二分图多重匹配)

    [题意] 假设一个试题库中有 n 道试题. 每道试题都标明了所属类别. 同一道题可能有多个类别属性.现要从题库中抽取 m 道题组成试卷.并要求试卷包含指定类型的试题. 试设计一个满足要求的组卷算法. ...

  7. 网络流24题 第五题 - PowerOJ1740 CodeVS1905 圆桌问题 二分图多重匹配 网络最大流

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - PowerOJ1740 - 有SPJ - 推荐 题目传送门 - CodeVS1905 - 无SPJ - 0% ...

  8. HDU 3605 Escape(二分图多重匹配问题)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  9. poj 2289 Jamie's Contact Groups【二分+最大流】【二分图多重匹配问题】

    题目链接:http://poj.org/problem?id=2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K ...

随机推荐

  1. react+dva+antd/antd-mobile

    github仓库pc: https://github.com/llcMite/react-dva-antd.git github仓库mobile:https://github.com/llcMite/ ...

  2. [转载] JAVA面试题和项目面试核心要点精华总结(想进大公司必看)

    JAVA面试题和项目面试核心要点精华总结(想进大公司必看) JAVA面试题和项目面试核心要点精华总结(想进大公司必看)

  3. flask-admin fileadmin 上传文件,中文名的解决方案 重写部分secure_filename

    class upload_view(FileAdmin): def _save_form_files(self, directory, path, form): super() filename = ...

  4. unordered_map/unordered_set & unordered_multimap/unordered_multiset非关联容器

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  5. 团队项目开发特点以及NABCD分析总结

    (注:此博客来源于韩晓凡,我们是一个团队) 团队项目的特点:开发的这款软件是从我们的日常生活中得到的启发,现在正是大学阶段,刚刚开始管理自己每个月的生活费,并且在大学中每个月的生活费会有很多去处,然而 ...

  6. 输入三个double型的数据,放入到a,b,c三个变量中去,使用条件结构与交换逻辑将这三个变量中的值从小到大排列。

    import java.util.Scanner; public class C8{ public static void main(String []args){ /* 8.输入三个double型的 ...

  7. log4j的参数配置(转)

    转载:log4j.properties文件各参数含义与配置   以下是配置文件log4j.properties的一些属性: log4j.rootLogger=WARN, stdout, Rlog4j. ...

  8. <Dr.Elephant><How to tune ur application>

    Why Dr.Elephant? Most of Hadoop optimization tools out there, but they are focused on simplifying th ...

  9. [SpringMVC-初始] 初始SpringMVC

    关于SpringMVC的简介 A.SpringMVC概述 作用: SpringMVC框架是SpringFramWork中实现了MVC架构模式的轻量级子框架 用于将WEB层进行职责解耦,松散的耦合可插拔 ...

  10. C# 解压

    需要ICSharpCode.SharpZipLib.dll 网上有很多 先添加文件引用 再添加引用 using ICSharpCode.SharpZipLib.Zip; #region 解压 /// ...