I can finally say that this is my own independent completion of the topic, did not see the problem, not read the notes, although the time to write, there is a sense of accomplishment, last night wrote a probably, a little bug, because too late, and a little sleepy, went to bed, then really himself seriously thought, and very deep thinking, Use the bit vectors that have just been learned in the book to judge by their own generation. In the future, we must strive to think, solve their own, focus ... Depth....
Ideas:
is to figure out a minimum of M lights to represent n numbers, and then find the number of the first number (a 0,1 sequence consisting of many lamps) of M
Set, the n subset as the subscript of n numbers, judging if there is no play to the same, if there is proof that these two numbers can not be judged by M lights
Break, then put M plus 1, find the first number of m+1 a subset, and m when the same judgment
Code:
#include <stdio.h> #include <string.h> #include <stdlib.h>int b[20];int sum;int map[105][20];int ans; int Res[20];int flag,n;void Find (int m,int *b,int cur) {if (flag) return; if (cur = = m) {if (ans!=sum) return; int k = 0;memset (r Es,0,sizeof (res)); for (int i=0; i<cur; i++) {if (B[i]) {res[k++] = i;}} Puts ("");//puts ("***********************");//for (int p=0; p<k; p++)//printf ("%d", res[p]);//puts (""); for (int i=0; i<n; i++) {for (int j=i+1; j<n; J + +) {int nodeng = 0;for (int p=0; p<k; p++) {//printf ("%d", res[p]); if (map[i][res[p]]!=map[ J][res[p]] {//printf ("II =%d JJ =%d\n", i,j),//printf ("k =%d\n", k),//printf ("p =%d\n", res[p]); Nodeng = 1;break;}} Puts ("**************"), if (nodeng==0) {//printf ("i =%d J =%d\n", i,j);//printf ("map[0][3] =%d map[8][3] =%d\n", map[0] [3],map[8][3]);//system ("pause"); return;}} Flag = 1;//puts ("***********************"); return;} B[cur] = 1;ans++;find (m,b,cur+1); B[cur] = 0;ans--;find (m,b,cur+1);} int main () {int t,m,i,j;scanf ("%d", &t); while(t--) {memset (b,0,sizeof (B)), memset (map,0,sizeof (map)), scanf ("%d%d", &m,&n),//m indicates the number of lights, n represents the number of digits for (i=0; i<n; i++) for (j=0; j<m; j + +) scanf ("%d", &map[i][j]);//printf ("**map[0][3] =%d map[8][3] =%d\n", map[0][3],map[8][3]) ; if (n==1) {printf ("%d\n", 0); continue;} if (m==0| | n==0) {printf ("%d\n", 0); continue;} int x = 1;ans = 0;for (i=1; i<=m; i++) {x*=2;if (x >= n) {x = I;break;}} printf ("x =%d\n", x), sum = X;flag = 0;for (sum=x; sum<=m; sum++) {find (m,b,0); if (flag) {printf ("%d\n", sum); break;}}} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 11205 The broken pedometer (brute force enumeration + subset Generation)