Ultraviolet A 11205 the broken Pedometer

Source: Internet
Author: User

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 ;
}

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.