• BZOJ1433: [ZJOI2009]假期的宿舍


    1433: [ZJOI2009]假期的宿舍

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 3134  Solved: 1324
    [Submit][Status][Discuss]

    Description

    Input

    Output

    Sample Input

    1
    3
    1 1 0
    0 1 0
    0 1 1
    1 0 0
    1 0 0

    Sample Output

    ˆ ˆ

    HINT

    对于30% 的数据满足1 ≤ n ≤ 12。
    对于100% 的数据满足1 ≤ n ≤ 50,1 ≤ T ≤ 20。

    #include<bits/stdc++.h>
    #define RG register
    #define il inline
    #define db double
    #define LL long long
    #define N 100000
    #define S 0
    #define Inf (1<<30)
    using namespace std;
    struct ed{int nxt,to,c;}e[N];
    int head[N],tot,dep[N];
    void link(int u,int v,int c){e[tot].nxt=head[u];e[tot].to=v;e[tot].c=c;head[u]=tot++;}
    void LINK(int u,int v,int c){link(u,v,c),link(v,u,0);}
    int n,BZ[N],cnt,out[N];
    void clear(){
      tot=0;memset(head,-1,sizeof(head));
      cnt=0;
    }
    bool BFS(int s,int t){
      memset(dep,0,sizeof(dep));
      dep[s]=1;queue<int>que;while(!que.empty())que.pop();que.push(s);
      while(!que.empty()){
        int u=que.front();
        que.pop();
        for(int i=head[u];i!=-1;i=e[i].nxt)
          if(!dep[e[i].to]&&e[i].c){
        int v=e[i].to;
        dep[v]=dep[u]+1;
        if(v==t)return true;
        que.push(v);
          }
      }return false;
    }
    int dinic(int s,int t,int T){
      if(s==t)return T;int tag(0);
      for(int i=head[s];i!=-1;i=e[i].nxt)if(dep[e[i].to]==dep[s]+1&&e[i].c){
          int v=e[i].to;
          int d=dinic(v,t,min(T-tag,e[i].c));
          e[i].c-=d,e[i^1].c+=d,tag+=d;
          if(tag==T)break;
        }if(!tag)dep[s]=0;
      return tag;
    }
    int maxflow(int s,int t){
      int flow(0);
      while(BFS(s,t))flow+=dinic(s,t,Inf);
      return flow;
    }
    int main(){
      int T;scanf("%d",&T);
      while(T--){
        clear();
        scanf("%d",&n);
        for(int i=1;i<=n;++i){
          scanf("%d",&BZ[i]);
          LINK(0,i,1);
        }
        for(int i=1;i<=n;++i){
          scanf("%d",&out[i]);
          if(BZ[i])LINK(i+n,2*n+1,1);
          if(BZ[i]&&out[i])cnt++;
        }
        for(int i=1;i<=n;++i){
          if(BZ[i]&&out[i])
          for(int j=1;j<=n;++j){
        int kk;scanf("%d",&kk);
        }
          else {
        LINK(i,i+n,1);
        for(int j=1;j<=n;++j){
          int kk;scanf("%d",&kk);
          if(kk)LINK(i,j+n,1);
        }
          }
        }
        if(maxflow(S,2*n+1)+cnt==n)cout<<"^_^
    ";
        else cout<<"T_T
    ";
      }
      return 0;
    }
    

    思路{首先用增广路的方法发现是有问题的,然后发现,人床对应,就是一个裸的二分图}

  • 相关阅读:
    《转》 在C++中使用TinyXML2解析xml
    基于多种转换语义的图数据库查询
    tomcat内存、连接数优化
    JAVA基础针对自己薄弱环节总结01(循环之前的知识)
    CodeForces
    N年的经验在别人眼里是怎么看的?
    perl install-module.pl DateTime 执行无效问题的解决
    在Linux上使用iptables命令开启对外访问的网络端口
    Linux上安装Bugzilla4.4小记
    在Lotus Notes设置邮件转发
  • 原文地址:https://www.cnblogs.com/zzmmm/p/7476540.html
Copyright © 2020-2023  润新知