You can make p rows different by using only a few columns. A violent DFS would be all right.
#include <stdio.h>#include<string.h>intN, p;//n column P rowintmap[ the][ -];intflaglie[ -];Chars[ the][ -];intsum;voidSouintans) { intI, C =0, j, flag =0; if(ans = =N) { for(i =0; I < P; i++) {C=0; for(j =0; J < N; J + +) { if(Flaglie[j] = =1) {S[i][c]= Map[i][j] +'0'; C++; }} S[i][c]=' /'; } for(i =0; I < P; i++) { for(j = i +1; J < P; J + +) { if(strcmp (S[i], s[j]) = =0) {flag=1; Break; } } } if(Flag = =0) {if(c < sum) sum =C;} return; } Flaglie[ans]=1; Sou (ans+1); Flaglie[ans]=0; Sou (ans+1);}intMain () {intI, J, SB, BS; scanf ("%d", &SB); for(bs =0; BS < SB; bs++) {scanf ("%d%d", &n, &p); Sum=N; for(i =0; I < P; i++) { for(j =0; J < N; J + +) {scanf ("%d", &Map[i][j]); }} sou (0); printf ("%d\n", sum); } return 0;}
UVA 11205 The Broken pedometer