zoukankan      html  css  js  c++  java
  • 【ZJOI2007】矩阵游戏

    题面

    https://www.luogu.org/problem/P1129

    题解

    // luogu-judger-enable-o2
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<vector>
    #include<queue>
    #define ri register int
    #define N 205
    using namespace std;
    
    inline int read() {
      int f=0,ret=0; char ch=getchar();
      while (ch<'0' || ch>'9') f|=(ch=='-'),ch=getchar();
      while (ch>='0'&& ch<='9') ret=ret*10+(ch-'0'),ch=getchar();
      return f?-ret:ret;
    }
    int T,n;
    vector<int> to[N];
    int match[N],vis[N],tin;
    
    bool dfs(int x) {
      for (ri i=0;i<to[x].size();i++) {
        int y=to[x][i];
        if (vis[y]==tin) continue;
        vis[y]=tin;
        if (!match[y] || dfs(match[y])) {
          match[y]=x;
          return 1;
        }
      }
      return 0;
    }
    
    void work() {
      n=read();
      for (ri i=1;i<=n;i++) to[i].clear();
      memset(match,0,sizeof(match));
      memset(vis,0,sizeof(vis));
      for (ri i=1;i<=n;i++)
        for (ri j=1;j<=n;j++) {
          int w=read();
          if (w) to[i].push_back(j);
        }
      tin=0;
      for (ri i=1;i<=n;i++) {
        ++tin;
        if (!dfs(i)) {
          puts("No");
          return;
        }
      }
      puts("Yes");
      return;
    }
    
    int main() {
      T=read();
      while (T--) work();
      return 0;
    }
  • 相关阅读:
    Express 框架中 使用ejs
    Nodejs操作MongoDB数据库
    MongoDB基础操作
    node中的包、npm和模块
    background
    animation
    transition
    transform
    【SpringCloud】各种组件的更新情况
    【SpringCloud】版本选择
  • 原文地址:https://www.cnblogs.com/shxnb666/p/11278604.html
Copyright © 2011-2022 走看看