Escape
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2523 accepted submission (s): 691
Problem description2012 if this is the end of the world how to do? I do not know how. but now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. now scientists want your help, is to determine what all of people can live in these planets.
Inputmore set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) N indicate there n people on the earth, M representatives M planet, planet and people labels are from 0. here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 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 1 1
1
1
2 2
1 0
1 0
1 1
Sample outputyes
No
ACM-ICPC multi-university training Contest (17) -- host by zstu
Recommendlcy is the most simple stream. However, the data is big and many templates have been tried, all of which are TLE. Later, we found that vertices can be merged because M <= 10. Therefore, binary records are used. In N points, if they are the same, they are merged. In this way, the maximum number is 1024 + m + 2 points. But this question is still very difficult .... In HDU, G ++ is used to deliver the data to TLE. To directly read data and output data, convert it to "C ++" and then "AC...
// ========================================================== ========================================== // Name: HDU. cpp // Author: // Version: // Copyright: Your copyright notice // Description: Hello world in C ++, ANSI-style // ========================================================== ========================================== # Include <Iostream> # Include < String . H> # Include <Algorithm> # Include <Stdio. h> Using Namespace STD; Const Int Maxn = 100110 ; Const Int Maxm = 4000110 ; Const Int INF = 0x3f3f3f ; Struct Node { Int To, next, cap;} edge [maxm]; Int Tol; Int Head [maxn]; Int Gap [maxn], DIS [maxn], pre [maxn], cur [maxn]; Void Init () {Tol = 0 ; Memset (Head, - 1 , Sizeof (Head ));} Void Addedge ( Int U, Int V, Int W, Int RW = 0 ) {Edge [tol]. = V; edge [tol]. Cap = W; edge [tol]. Next = head [u]; head [u] = tol ++ ; Edge [tol]. = U; edge [tol]. Cap = RW; edge [tol]. Next = head [v]; head [v] = tol ++ ;} Int SAP ( Int Start,Int End, Int Nodenum) {memset (DIS, 0 , Sizeof (DIS); memset (gap, 0 , Sizeof (GAP); memcpy (cur, Head, Sizeof (Head )); Int U = pre [start] = start, maxflow = 0 , Aug =- 1 ; Gap [ 0 ] = Nodenum; While (DIS [start] < Nodenum) {loop: For ( Int & I = cur [u]; I! =- 1 ; I = Edge [I]. Next ){ Int V = Edge [I].; If (Edge [I]. Cap & dis [u] = dis [v] + 1 ){ If (Aug =- 1 | Aug> Edge [I]. Cap) Aug = Edge [I]. CAP; Pre [v] = U; u = V; If (V = End) {maxflow + = Aug; For (U = pre [u]; V! = Start; V = u, u =Pre [u]) {edge [cur [u]. Cap -= Aug; edge [cur [u] ^ 1 ]. Cap + = Aug;} Aug =- 1 ;} Goto Loop ;}} Int Mindis = Nodenum; For ( Int I = head [u]; I! =- 1 ; I = Edge [I]. Next ){ Int V = Edge [I].; If (Edge [I]. Cap & mindis> Dis [v]) {cur [u] = I; mindis = Dis [v] ;}} If (-- Gap [dis [u]) = 0 ) Break ; Gap [dis [u] = Mindis + 1 ] ++ ; U = Pre [u];} Return Maxflow ;} Int Num [ 1025 ]; Int A [ 11 ]; Int Bit [ 11 ]; Int Main (){ // Freopen ("in.txt", "r", stdin ); // Freopen ("out.txt", "W", stdout ); Bit [ 0 ] = 1 ; For ( Int I = 1 ; I <= 10 ; I ++) bit [I] = bit [I- 1 ] * 2 ; Int N, m; While (Scanf ( " % D " , & N, & M )! = EOF) {Init (); memset (Num, 0 , Sizeof (Num )); For ( Int I = 1 ; I <= N; I ++){ Int TMP = 0 ; For ( Int J = 0 ; J <m; j ++) {scanf ( " % D " , & A [J]); TMP + = A [J] * Bit [J];} num [TMP] ++ ;} Int Start = 0 , End =1024 + M + 1 , Nodenum = 2014 + M + 2 ; For ( Int I = 0 ; I < 1024 ; I ++ ){ If (Num [I] = 0 ) Continue ; Addedge (start, I +1 , Num [I]); For ( Int J = 0 ; J < 10 ; J ++ ) If (I & Bit [J]) addedge (I + 1 , 1024 + J + 1 , INF );} Int TMP; For ( Int I = 1 ; I <= m; I ++ ) {Scanf ( " % D " ,& TMP); addedge (I + 1024 , End, TMP );} If (SAP (START, end, nodenum) = N) printf ( " Yes \ n " ); Else Printf ( " No \ n " );} Return 0 ;}