BZOJ대시야1059: [ZJOI2007] 매트릭스 게임 문제풀이 보고서

4468 단어 이분도 일치BZOJ
이분도가 일치하고, 줄로 열을 일치시킵니다.
code: /**************************************************************      Problem: 1059      Language: C++      Result: Accepted      Time:316 ms      Memory:1744 kb ****************************************************************/     // Forever_LF #include #include #include using namespace std;     struct node {      int x,y,next; }a[40001]; int len,first[201]; int L[201]; bool ev[201];     void ins( int x, int y ) {      len++;      a[len].x=x; a[len].y=y;       a[len].next = first[x]; first[x] = len; } bool ex( int x ) {      for ( int k=first[x];k;k=a[k].next )      {          int y=a[k].y;          if ( ev[y] ) continue ;          ev[y] = true ;          if ( !L[y] || ex( L[y] ) )          {              L[y] = x;              return true ;          }      }      return false ; }     int main() {      int n,m,t,i,j,l;      bool v;      scanf ( "%d" ,&m);      while ( m-- )      {          memset ( first,0, sizeof first );          memset ( L,0, sizeof L );          len = 0; v = true ;                      scanf ( "%d" ,&n);          for ( i=1;i<=n;i++ )              for ( j=1;j<=n;j++ )              {                  scanf ( "%d" ,&l);                  if ( l ) ins( i,j );              }          for ( i=1;i<=n;i++ )          {              memset ( ev, false , sizeof ev );              if ( !ex( i ) )              {                  v = false                  break ;              }          }          if ( v ) printf ( "Yes
"
);          else printf ( "No
"
);      }      return 0; }

좋은 웹페이지 즐겨찾기