UVa 11025 The broken pedometer "enumeration subset"

Source: Internet
Author: User

Test instructions: Give a matrix, the matrix is represented by the n number of binary, p indicates that a number of digits represented by the P-bit binary can be separated by a minimum of how many columns will be used to divide the n number.

Enumerate subsets, and then count the number of columns used for each subset, maintaining a minimum value

B[i]==1 represents the choice of this column.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A  - #defineforeach (I,c) for (__typeof (C.begin ()) i = C.begin (); I! = C.end (); ++i) -  thetypedefLong LongLL; - Const intINF = (1<< -)-1; - Const intMod=1000000007; - Const intmaxn=100005; +  - intb[maxn],a[505][505]; + intminn,n,p; A  at voidsolve () { -      for(intI=0; i<n-1; i++){         -          for(intj=i+1; j<n;j++){ -             intflag=0;  -              for(intk=0; k<p;k++) -                 if(B[k]&&a[i][k]!=a[j][k]) flag=1;//B[k]==1 represents the choice of this column . in  -             if(flag==0)return; to         }         +     } -      the     intans=0; *      for(intI=0; i<p;i++) $     if(B[i]) ans++;Panax Notoginseng      - //printf ("ans=%d\n", ans); the //printf ("minn=%d\n", Minn); +minn=min (minn,ans); A } the  + voidSubset (intcur) { -     if(cur==p) { $ solve (); $         return; -     } -b[cur]=1; theSubset (cur+1); -b[cur]=0;WuyiSubset (cur+1);  the }  -  Wu intMain () { - //freopen ("In.txt", "R", stdin); About //freopen ("OUT.txt", "w", stdout); $     intT; -Cin>>T; -          while(t--){ -Cin>>p>>N; A              for(intI=0; i<n;i++) +               for(intj=0; j<p;j++) theCin>>A[i][j]; -               $minn=p; theSubset (0); theprintf"%d\n", Minn); the         } the     return 0;  -}
View Code

I did not read the topic----SAD------------

Refueling--

UVa 11025 The broken pedometer "enumeration subset"

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.