science!Time
limit:5000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 415 Accepted Submission (s): 116
Special Judge
Problem descriptionwelcome, ladies and gentlemen, to Aperture science. Astronauts, War Heroes, Olympians-you ' re here because we want the best, and you are it. That's said, it ' s time to make some.
Now, I want each of the stand on one of the these buttons. Well done, we ' re making great progress here. Now let's do it again. Oh, come On-don ' t stand on the same button! Move, people! No, no, that button's only for the astronauts, you know. what?! You say can ' t do everything I ask? Ok let's start over. You there, the Programmer, figure out how to many times we can do this. and make it quick, we had a lot more science to get through ...
Inputthere'll is several test cases in the input. The first line of all case would contain
N(2≤
N≤80) giving the number of people (and the number of buttons) in the experiment. The next
NLines'll contain
NCharacters each. If the jth character of the ith line is
YIt indicates the ith person can stand on the jth button (it's
Notherwise). The last line of input would be a 0.
Outputfor each test case, output
k, the maximum number of times everyone can be standing on buttons such that nobody stands on the same button more than Onc E (This might is 0). After, output
kLines. Each line should contain
Nintegers separated by single spaces, where the ith integer describes which person is standing on the ith button. All of the lines should is valid and none of the them should put the same person on the same button as a previous line of the Same test case. Output no extra spaces, and do not separate answers with blank lines. Note that correct outputs might is unique.
Sample Input
3yyynyyyny2ynyn0
Sample Output
23 1 21) 2 30
Sourcethe University of Chicago Invitational programming Contest 2012
recommendliuyiding | We have carefully selected several similar problems for you:5390 5389 5388 5387 5386
Two-point answer network Flow, find out K.
Remove extra edges,
Next k times,
Each time you find the maximum binary image match on the original, delete the Edge,
Get a workable solution
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include < functional> #include <iostream> #include <cmath> #include <cctype> #include <ctime>using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (I,k,n) for (int. i=k;i<=n;i++) #define REP (I,n) for (int i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (I,n) for (int. i=n;i>=0;i--) #define FORP (x) for ( int p=pre[x];p; p=next[p]) #define FORPITER (x) for (int &p=iter[x];p; p=next[p]) #define LSON (x<<1) #define Rson ((x<<1) +1) #define MEM (a) memset (A,0,sizeof (a)), #define MEMI (a) memset (A,127,sizeof (a)), #define MEMI (a) memset ( A,128,sizeof (a)), #define INF (2139062143) #define F (100000007) #define MAXN (80+10) #define MAXN (500+19) #define MAXM ( 69999+100) long long mul (long long A,long long B) {return (a*b)%F;} Long Long (long A,long long B) {return (a+b)%F;} Long Long sub (long A,long long B) {return (a-b+ (a)/f*f+f)%F;} typedef LONG Long Ll;class max_flow//dinic+ current arc optimization {public:int n,s,t; int Q[MAXN]; int edge[maxm],next[maxm],pre[maxn],weight[maxm],size; void Addedge (int u,int v,int W) {edge[++size]=v; Weight[size]=w; Next[size]=pre[u]; Pre[u]=size; } void Addedge2 (int u,int v,int W) {Addedge (u,v,w), Addedge (v,u,0);} BOOL B[MAXN]; int D[MAXN]; BOOL SPFA (int s,int t) {for (i,n) D[i]=inf; MEM (b) d[q[1]=s]=0;b[s]=1; int head=1,tail=1; while (head<=tail) {int now=q[head++]; Forp (now) {int &v=edge[p]; if (Weight[p]&&!b[v]) {d[v]=d[now]+1; B[v]=1,q[++tail]=v; } } } return b[t]; } int ITER[MAXN]; int dfs (int x,int f) {if (x==t) return F; Forpiter (x) {int v=edge[p]; if (Weight[p]&&d[x]<d[v]) {int Nowflow=dfs (v,min (weight[p],f)); if (nowflow) {weight[p]-=nowflow; Weight[p^1]+=nowflow; return nowflow; }}} return 0; } int Max_flow (int s,int t) {int flow=0; while (SPFA (s,t)) {for (i,n) iter[i]=pre[i]; int F; while (F=dfs (S,inf)) flow+=f; } return flow; } void mem (int n,int s,int t) {(*this). N=n; (*this). t=t; (*this). S=s; size=1; MEM (PRE)}}s; Char S[maxn][maxn];iNT N;bool Check (int m) {s.mem (2*n+2,1,2*n+2); for (I,n) S.addedge2 (1,i+1,m), S.addedge2 (n+1+i,2*n+2,m); for (I,n) for (j,n) if (s[i][j]== ' Y ') s.addedge2 (1+i,n+1+j,1); if (S.max_flow (1,2*n+2) ==n*m) return 1;return 0;} int Ans[maxn];int Main () {//freopen ("hdu4265.in", "R", stdin),//freopen (". Out", "w", stdout) and while (scanf ("%d", &n) ==1) {if (!n) break; for (I,n) scanf ("%s", s[i]+1), int l=0,r=n,ans=0;while (l<=r) {int m= (l+r) >>1;if (check (m)) Ans=m,l=m+1;else r= M-1;} Check (ANS);p rintf ("%d\n", ans); Fork (i,2,n+1) {for (int p=s.pre[i];p; p=s.next[p]) if (! s.weight[p^1]&&s.edge[p]>n+1) s[i-1][s.edge[p]-n-1]= ' n '; }while (ans--) {s.mem (2*n+2,1,2*n+2); for (I,n) S.addedge2 (1,i+1,1), S.addedge2 (n+1+i,2*n+2,1); for (I,n) for (j,n) if (s[i][j]== ' Y ') s.addedge2 (1+i,n+1+j,1); S.max_flow (1,2*n+2); Fork (i,2,n+1) {for (int p=s.pre[i];p; p=s.next[p]) if (! s.weight[p]&&s.edge[p]>n+1) {ans[s.edge[p]-n-1]=i-1,s[i-1][s.edge[p]-n-1]= ' n '; break;}} for (i,n-1) printf ("%d", Ans[i]);p rintf ("%d\n", Ans[n]);}} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 4265 (science!-two-part network stream)