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"