Let's talk about:
At the beginning of this question, I thought there was an error. I thought that as long as I had to judge each bit, that is, if the bit of each number is not considered, if two numbers are identical, this bit must exist. Otherwise, it is dispensable. However, this is actually a problem, because it means that the judgment of a person is based on other places by default. In fact, it is reasonable to judge the bit to be judged after all invalid bits are removed, but this is obviously not satisfactory. Therefore, I also read some other people's Problem Solving Report on the Internet. The simplest thing is to use the bitvector method. That is, to determine whether each bit of P is effectively arranged and combined, list all the situations, and solve the problem by brute force.
Source code:
# Include <stdio. h> # include <string. h> # define maxp 15 + 5 # define maxn 100 + 5int s [maxn] [maxp]; char CPY [maxn] [maxp]; char valid [maxp]; int N, p, ans; void solve (INT cur) {int I, j, count; If (cur = P) {COUNT = 0; // record the number of valid bits for (I = 0; I <p; I ++) if (valid [I]) {// fill in count ++; For (j = 0; j <n; j ++) based on the obtained data) CPY [J] [I] = '0' + s [J] [I];} else for (j = 0; j <n; j ++) // The invalid bit is directly set to 0 CPY [J] [I] = '0'; for (I = 0; I <n; I ++) CPY [I] [p] = '\ 0'; // do not forget to put the end ID of the string for (I = 0; I <n; I ++) for (j = I + 1; j <n; j ++) if (strcmp (CPY [I], CPY [J]) = 0) // If a duplicate is found, this sorting method does not support return; If (count <ans) ans = count; return;} valid [cur] = 0; // bit vector method, list all cases solve (cur + 1); valid [cur] = 1; solve (cur + 1); return;} int main () {int I, J, K, t; // freopen ("data", "r", stdin); scanf ("% d", & T); While (t --) {scanf ("% d", & P, & N); for (I = 0; I <n; I ++) for (j = 0; j <p; j ++) scanf ("% d", & S [I] [J]); ans = P; solve (0 ); printf ("% d \ n", ANS);} return 0 ;}
The broken pedometer ultraviolet A 11205