博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3605(二分图的多重匹配 | 网络流)
阅读量:4946 次
发布时间:2019-06-11

本文共 4090 字,大约阅读时间需要 13 分钟。

 一开始以为这题是二分图的匹配,然后用匈牙利做,TLE,然后用HK 做, TLE。。。

最后发现是用网络流做的,而且要将100000个点压缩, 因为每个点的可能选择情况有2^10 ,所以根据这个可以将图压缩成1000*10大小的图,这样用网络流就没有压力了...

网络流建模很重要.! 

 

Escape

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2483    Accepted Submission(s): 687

Problem Description
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.
 

 

Input
More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet.
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
0 <= ai <= 100000
 

 

Output
Determine whether all people can live up to these stars
If you can output YES, otherwise output NO.
 

 

Sample Input
1 1 1 1 2 2 1 0 1 0 1 1
 

 

Sample Output
YES NO
 

 

Source
 

 

Recommend
lcy
 

 

Escape

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2483    Accepted Submission(s): 687

Problem Description
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.
 

 

Input
More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet.
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
0 <= ai <= 100000
 

 

Output
Determine whether all people can live up to these stars
If you can output YES, otherwise output NO.
 

 

Sample Input
1 1 1 1 2 2 1 0 1 0 1 1
 

 

Sample Output
YES NO
 

 

Source
 

 

Recommend
lcy
 

 

#include 
#include
#include
using namespace std;#define N 100100#define K 1111#define INF 0x3fffffffstruct node{ int to,next,w;}edge[N];int cnt,pre[2200];int n,m;int s,t;int g[N][11];int save[2200];int tt;int gap[2200],lv[2200];void add_edge(int u,int v,int w){ edge[cnt].to=v; edge[cnt].w=w; edge[cnt].next=pre[u]; pre[u]=cnt++;}int sdfs(int k,int w){ if(k==t) return w; int f=0; int mi=tt; for(int p=pre[k];p!=-1;p=edge[p].next) { int v=edge[p].to; if(edge[p].w!=0) { if( lv[k]==lv[v]+1 ) { int tmp=sdfs(v,min(edge[p].w,w-f)); f += tmp; edge[p].w -= tmp; edge[p^1].w += tmp; if( f==w || lv[s]==tt ) return f; } if(lv[v] < mi) mi=lv[v]; } } if(f==0) { gap[lv[k]]--; if( gap[lv[k]]==0 ) { lv[s]=tt; return 0; } lv[k]=mi+1; gap[lv[k]]++; } return f;}int sap(){ int sum=0; tt=t+1; memset(gap,0,sizeof(gap)); memset(lv,0,sizeof(lv)); gap[0]=tt; while(lv[s]
>= 1; } } } for(int i=1;i<=m;i++) { int tmp; scanf("%d",&tmp); add_edge(K+i,t,tmp); add_edge(t,K+i,0); } if(sap()==n) printf("YES\n"); else printf("NO\n"); } return 0;}

 

转载于:https://www.cnblogs.com/chenhuan001/archive/2013/05/01/3053251.html

你可能感兴趣的文章
Bootstrap简单介绍
查看>>
iOS Touch ID 身份认证
查看>>
springboot 注解笔记
查看>>
图解HTTP---------------------------------------4
查看>>
rsync+inotify脚本
查看>>
文件上传
查看>>
(Problem 92)Square digit chains
查看>>
0809
查看>>
FineUIPro v5.2.0已发布(jQuery升级,自定义图标,日期控件)
查看>>
智能合约安全前传-基础知识入门
查看>>
Myeclipse反编译插件
查看>>
Dubbo和Zookerper的关系
查看>>
centos 5 系统安装MYSQL5.7
查看>>
docker数据卷(转)
查看>>
地图定位及大头针设置
查看>>
oracle常用小知识点
查看>>
CATransform3D参数的意义
查看>>
怎么自己在Objective-C中创建代理
查看>>
Under Armour Drive 4 Performance Reviews
查看>>
C#操作目录和文件
查看>>