"bzoj4443" [Scoi2015] small convex play matrix

Source: Internet
Author: User

The K-Large is n-k+1 small, so you can answer the two points (Jianggo said a similar question)

The two-point answer finds the coordinates of the position of the number that is smaller than the current answer, determines whether the n-k+1 number that satisfies the same column in the same row can be selected, and then runs Hungary, and for a coordinate (x, y) if the current answer to A[x][y]≤a[x][y is met, the line x is connected to the Y column, Then run Hungary to determine if the maximum match is greater than n-k+1

#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #include<queue> #include<set> using namespace std; #define M 300 #define N 1000001 struct edge {      int v,next; }e[N<<1]; int head[N<<1]; int cnt; int map[M][M]; int ly[N],f[N]; int n,m,k; int l,r; int maxn,tot,ans; void link( int x, int y) {      e[++cnt]=(edge){y,head[x]};      head[x]=cnt; } bool find( int d) {      for ( int i=head[d];i;i=e[i].next)      {          int t=e[i].v;          if (ly[t]!=tot)          {              ly[t]=tot;              if (!f[t] || find(f[t]))              {                  f[t]=d;                  return true ;              }          }      }      return false ; } int work( int x) {      ans=cnt=0;      memset (head,0, sizeof (head));      memset (f,0, sizeof (f));      for ( int i=1;i<=n;i++)          for ( int j=1;j<=m;j++)              if (map[i][j]<=x)                  link(i,j);      for ( int i=1;i<=n;i++)      {          tot++;          ans+=find(i);      }      return ans>=k ? 1: 0; } int main() {      scanf ( "%d%d%d" ,&n,&m,&k);      k=n-k+1;      for ( int i=1;i<=n;i++)          for ( int j=1;j<=m;j++)              scanf ( "%d" ,&map[i][j]),maxn=max(maxn,map[i][j]);      l=1;      r=maxn;      while (l<r)      {          int m=l+r>>1;          if (work(m))              r=m;          else              l=m+1;      }      printf ( "%d\n" ,l);      return 0; }

"bzoj4443" [Scoi2015] small convex play matrix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.