Original title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3605
Escape
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 7145 Accepted Submission (s): 1553
Problem Description2012 If This is the end of the world? I don't know how. But now scientists has found that some stars, who can live, but some people does not fit to live some of the planet. Now scientists want your help, was to determine what's all of the people can live in these planets.
Inputmore set of test data, the beginning of each data is n (1 <= n <= 100000), M (1 <= m <=) n indicate th ere n people on the Earth, M representatives M planet, planet and people labels is from 0. Here's n lines, each line represents a suitable living conditions of people with each row have m digits, the ith digits is 1, said that's a person was fit to live in the Ith-planet, or was 0 for this person is not suitable for living in the ith planet .
The last line has m. digits, the ith digit AI indicates the ith planet can contain AI people most.
0 <= ai <= 100000
Outputdetermine whether all people can live up to these stars
If You can output YES, otherwise output NO.
Sample INPUT1 1112 21 01 01 1
Sample Outputyesno
Source2010 acm-icpc multi-university Training Contest (+)--host by Zstu test instructions
Earth people want to emigrate, tell you what the habitable planet is, each planet has a capacity to ask if you can arrange for everyone to emigrate.
Exercises
This is a very very very day dog problem .... Because of the small number of planets, many people, it is easy to think of people living conditions like pressure, and then build the map. This is still a T, why is it? Because the face is black ... After trying a variety of input hang, finally 998ms past, God has eyes.
Code
#include <iostream>#include<stack>#include<vector>#include<cstring>#include<string>#include<algorithm>#include<cstdio>#include<queue>#definemax_s (1<<10) +10#defineMax_v 1222#defineMax_n Max_v#defineINF 2500005using namespacestd;structEdge {intto, Cap, rev; BOOLIsrev; Edge (intTintCintRBOOLi): to (t), Cap (c), Rev (R), Isrev (i) {} edge () {}};template<classT>inlineBOOLScan_d (T &ret) { CharC; intSGN; if(C=getchar (), c==eof)return 0;//EOF while(c!=' -'&& (c<'0'|| C>'9')) c=GetChar (); SGN= (c==' -')?-1:1; RET= (c==' -')?0:(C-'0' ); while(C=getchar (), c>='0'&&c<='9') ret=ret*Ten+ (C-'0' ); RET*=SGN; return 1;} Vector<edge>G[max_n];intLevel[max_v];intIter[max_v];voidInitintTotnode) { for(inti =0; I <= Totnode; i++) g[i].clear (); Memset (Level,0,sizeof(level)); memset (ITER,0,sizeof(ITER));}voidAdd_edge (int from,intTo,intcap) {g[ from].push_back (Edge (To, Cap, g[to].size (),0)); G[to].push_back (Edge ( from,0, g[ from].size ()-1,1));}voidBFsints) {queue<int>que; Memset (Level,-1,sizeof(level)); Level[s]=0; Que.push (s); while(!Que.empty ()) { intv =Que.front (); Que.pop (); for(inti =0; I < g[v].size (); i++) {Edge&e =G[v][i]; if(E.cap >0&& Level[e.to] <0) {level[e.to]= Level[v] +1; Que.push (e.to); } } }}intDfsintVintTintf) {if(v = = t)returnF; for(int&i = Iter[v]; I < g[v].size (); i++) {Edge&e =G[v][i]; if(E.cap >0&& Level[v] <Level[e.to]) { intD =dfs (e.to, T, Min (f, e.cap)); if(D >0) {E.cap-=D; G[e.to][e.rev].cap+=D; returnD; } } } return 0;}intMax_flow (intSintt) {intFlow =0; for (; ;) {BFS (s); if(Level[t] <0)returnflow; memset (ITER,0,sizeof(ITER)); intF; while(f = DFS (S, T, INF)) >0) {Flow+=F; } }}intn,m;ints=1113;intt=1114;intcnt[max_s];intMain () { while(SCANF ("%d%d", &n, &m)! =EOF) {init (T+5); memset (CNT,0,sizeof(CNT)); for(inti =0; I < n; i++) { ints =0; for(intj =0; J < M; J + +) { intT; Scan_d (t); if(t) s |= (1<<j); } Cnt[s]++; } for(inti =0; I < (1<< m); i++) { if(Cnt[i]) {Add_edge (S, I, cnt[i]); for(intj =0; J < M; J + +) if((1<< j) &i) Add_edge (i, J+ (1<<m), Cnt[i]); } } for(inti =0; I < m; i++) { intT; Scan_d (t); Add_edge (i+ (1<<m), T, T); } intf =Max_flow (S, T); if(f = =N) printf ("yes\n"); Elseprintf ("no\n"); } return 0;}
HDU 3605 Escape max Flow + shape pressure