Test instructions: There is a set of encodings that differentiate these encodings with the least number of bits.
Idea: the equivalent of enumerating all the subsets of a collection, and then selecting the smallest set of potential that meets the requirements.
There are three methods for subset generation, but the generation of each subset has no obvious regularity, at least not from the order of 1 elements, 2 elements to n elements, so it is necessary to enumerate all the subsets. The increment constructor is used here to enumerate the subsets.
Code:
#include <stdio.h>void print_subset (int p,int n,int *a, int cur); bool Have_same (int cur,int n); int codi[101][16]; int A[15+5];int Min;int Main () {//freopen ("11205.in", "R", stdin); Freopen ("11205.out", "w", stdout); int t; scanf ("%d", &t); while (t-->0) {min=20; int p,n; scanf ("%d%d", &p,&n); for (int i=0;i<n;++i) for (int j=0;j<p;++j) {scanf ("%d", &codi[i][j]); } print_subset (p,n,a,0); printf ("%d\n", min); } return 0; }void print_subset (int p,int n,int *a, int cur) {if (cur && have_same (cur,n) ==false) min=cur<min?cur:min; int s=cur? a[cur-1]+1:0; for (int i=s;i<p;++i) {a[cur]=i; Print_subset (p,n,a,cur+1); }}bool have_same (int cur,int n) {for (int. i=0;i<n;++i) {for (int j=i+1;j<n;++j) {bool flag=true;//labeled COD I line I of array I and line J is the same as for (int m=0;m<cur;++m) {if (Codi[i][a[m]]!=codi[j][a[m]]) {flag=false; } if (flag) return true; } } return false; }
UVa 11205 Damaged Step count