HDU 3605 Escape
2014-08-31 16:41
225 查看
//author: CHC //First Edit Time: 2014-08-10 15:08 //Last Edit Time: 2014-08-10 15:26 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <set> #include <vector> #include <map> #include <queue> #include <set> #include <algorithm> #include <limits.h> using namespace std; typedef long long LL; const int MAXN=1e+4; const int MAXM=1e+5; const int INF = INT_MAX; //const LL LL_INF = LONG_LONG_MAX; struct Edge { int from,to,ci,next; Edge(){} Edge(int _from,int _to,int _ci,int _next):from(_from),to(_to),ci(_ci),next(_next){} }e[MAXM]; int head[MAXN],tot; int dis[MAXN]; int top,sta[MAXN],cur[MAXN]; int n,m; inline void init(){ memset(head,-1,sizeof(head)); tot=0; } inline void AddEdge(int u,int v,int ci0,int ci1=0){ e[tot]=Edge(u,v,ci0,head[u]); head[u]=tot++; e[tot]=Edge(v,u,ci1,head[v]); head[v]=tot++; } inline bool bfs(int st,int et){ memset(dis,0,sizeof(dis)); dis[st]=1; queue <int> q; q.push(st); while(!q.empty()){ int now=q.front(); q.pop(); for(int i=head[now];i!=-1;i=e[i].next){ int next=e[i].to; if(e[i].ci&&!dis[next]){ dis[next]=dis[now]+1; if(next==et)return true; q.push(next); } } } return false; } LL Dinic(int st,int et){ LL ans=0; while(bfs(st,et)){ //printf("here\n"); top=0; memcpy(cur,head,sizeof(head)); int u=st,i; while(1){ if(u==et){ int pos,minn=INF; //printf("top:%d\n",top); for(i=0;i<top;i++) { if(minn>e[sta[i]].ci){ minn=e[sta[i]].ci; pos=i; } //printf("%d --> %d\n",e[sta[i]].from,e[sta[i]].to); } for(i=0;i<top;i++){ e[sta[i]].ci-=minn; e[sta[i]^1].ci+=minn; } top=pos; u=e[sta[top]].from; ans+=minn; //printf("minn:%d\n\n",minn); } for(i=cur[u];i!=-1;cur[u]=i=e[i].next) if(e[i].ci&&dis[u]+1==dis[e[i].to])break; if(cur[u]!=-1){ sta[top++]=cur[u]; u=e[cur[u]].to; } else { if(top==0)break; dis[u]=0; u=e[sta[--top]].from; } } } return ans; } int has[1<<11]; int tt[20]; set <int> s; set <int> ::iterator it; int main() { while(~scanf("%d%d",&n,&m)){ init(); memset(has,0,sizeof(has)); s.clear(); for(int i=1;i<=n;i++){ int t=0,x; for(int j=0;j<m;j++){ scanf("%d",&x); t|=(x<<j); } if(!has[t])s.insert(t); ++has[t]; } for(int i=0;i<m;i++) scanf("%d",&tt[i]); int st=1024,et=1025; //0~1023 人的集合 //1024 st //1025 et //1026~1026+m-1 星球 //st-->人的集合 for(it=s.begin();it!=s.end();it++){ AddEdge(st,*it,has[*it]); } //人的集合-->星球 for(it=s.begin();it!=s.end();it++){ for(int i=0;i<m;i++) if((*it>>i)&1){ AddEdge(*it,1026+i,has[*it]); } } //星球-->et for(int i=0;i<m;i++) AddEdge(1026+i,et,tt[i]); LL ans=Dinic(st,et); if(ans==(LL)n)puts("YES"); else puts("NO"); } return 0; }
相关文章推荐
- HDU 3605 Escape (最大流+合并点)
- hdu 3605 Escape (二分图多重匹配)
- HDU 3605 Escape (二分图多重匹配模板)
- HDU-3605 Escape
- hdu 3605 Escape 多重匹配模板 (Hungary ) | 最大流
- HDU 3605 Escape(最大流+状态压缩)
- hdu 3605 Escape/poj 2584 T-Shirt Gumbo(二分图多重匹配)
- HDU 3605 Escape
- HDU 3605 Escape 最大流,状压
- hdu 3605 Escape 二分图的多重匹配(匈牙利算法)
- HDU_3605_Escape(多重匹配 / 网络流)
- HDU 3605 Escape【二分图多重匹配】
- HDU 3605 Escape 最大流
- hdu 3605 Escape【二分图多重匹配】
- HDU--3605 Escape (多重匹配)
- HDU 3605 Escape (二分图多重匹配模板)
- Escape HDU - 3605
- HDU -- 3605 Escape(最大流 状态合并判满流)
- Escape HDU - 3605 (最大流)(多重匹配)
- HDU 3605Escape(缩点+网络流之最大流)