Uva_11205
At the beginning, I encountered a serious problem in understanding the meaning of the question. Later I came up with someone else's report saying that the minimum number of columns in the given matrix can be selected to distinguish each row. In other words, it is actually Liu rujia's book.P120.
After about one day, I finally figured out what it means to select the least columns in the given matrix so that each row can be distinguished. After that, I would enumerate the combinations of all possible columns, if the requirements are met, update indicates the minimum number of ColumnsMinYou can.
# Include < Stdio. h >
# Include < String . H >
Int A [ 110 ] [ 20 ], P, N, hash [ 100000 ], FAC [ 20 ];
Int Main ()
{
Int I, J, K, T, Min, sum, num, OK;
FAC [ 0 ] = 1 ;
For (I = 1 ; I < 20 ; I ++ )
FAC [I] = 2 * FAC [I - 1 ];
Scanf ( " % D " , & T );
While (T -- )
{
Scanf ( " % D " , & P, & N );
For (I = 0 ; I < N; I ++ )
For (J = 0 ; J < P; j ++ )
Scanf ( " % D " , & A [I] [J]);
Min = 1000000000 ;
For (I = 0 ; I < ( 1 < P); I ++ )
{
Memset (hash, 0 , Sizeof (Hash ));
Num = 0 ;
For (K = 0 ; K < P; k ++ )
If (I & ( 1 < K ))
Num ++ ;
OK = 1 ;
For (J = 0 ; J < N; j ++ )
{
Sum = 0 ;
For (K = 0 ; K < P; k ++ )
If (I & ( 1 < K ))
Sum + = FAC [k] * A [J] [k];
If (Hash [Sum] = 0 )
Hash [Sum] = 1 ;
Else
{
OK = 0 ;
Break ;
}
}
If (OK && Num < Min)
Min = Num;
}
Printf ( " % D \ n " , Min );
}
Return 0 ;
}