4443: [Scoi2015] small convex play matrix

Source: Internet
Author: User

4443: [Scoi2015] small convex play matrixDescriptionsmall Convex and Xiao Fang is a good friend, small square to small convex a n*m (n<=m) matrix A, ask for a small bald from which n number, where any two numbers can not be in the same row or the same column, now the small convex want to know the number of the selected n number of K the minimum value is how much. Inputthe first line gives three integers n,m,knext n rows, m numbers per line, to describe this matrixOutputtitleSample Input3 4 2
1 5 6 6
8 3 4 3
6 8 6 3Sample Output3HINT

1<=k<=n<=m<=250,1<= Matrix Element <=10^9

acty really big God!!! (Everyone is free to go to the Bzoj to search)————— the following ——————It is easy to see that the answer is two-point. The title said is the first k big, actually is the first n-k+1 small (always see wrong) ... every time we verify the mid, we put the number of <=mid in the matrix about coordinates, run the maximum match of the binary graph, and judge whether the maximum match number is greater than n-k+1.
#include <stdio.h>#include<iostream>#include<algorithm>using namespacestd;Const intn=255;intN,m,k,i,j,ans,a[n][n],f[n],p[n];inttot,head[n],next[n*n],to[n*N];voidAddintXinty) {Tot++; To[tot]=y; Next[tot]=Head[x]; HEAD[X]=tot;}intDfsintXintT) {    inti;  for(i=head[x];i!=-1; i=Next[i])if(p[to[i]]!=T) {inty=To[i]; P[y]=T; if(f[y]==0||DFS (F[Y],T)) {F[y]=x; return 1; }    }    return 0;}intErfen (intLintR) {    if(L>r)returnl; intMid= (l+r) >>1, i,j,ans=0; Tot=0;  for(i=1; i<=n;i++) Head[i]=-1;  for(i=1; i<=m;i++) P[i]=f[i]=0;  for(i=1; i<=n;i++)      for(j=1; j<=m;j++)     if(a[i][j]<=mid) Add (I,J);  for(i=1; i<=n;i++) ans+=DFS (i,i); if(ans>=n-k+1)returnErfen (l,mid-1);Else    returnErfen (mid+1, R);}intMain () {scanf ("%d%d%d",&n,&m,&k);  for(i=1; i<=n;i++)      for(j=1; j<=m;j++) {scanf ("%d",&A[i][j]); Ans=Max (ans,a[i][j]); } cout<<erfen (1, ans); return 0;}

4443: [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.