I read a question last year, but I was dumb about using DFS + circular linked list. It's silly. But now I have been thinking about this question for a long time and there are still several times of Wa. In fact, this question is still very watery. Simply perform brute-force enumeration. The premise of enumeration is to calculate the complexity. We can know that for 01 strings with a length of N and K whose length is m, A maximum of M 0or1 values can be added to obtain a total number of K values. You can then enumerate from K * 1, K * 2, K * 3. We can see that you only need to enumerate 2 ^ 20 times at most. The complexity of 10 ^ 7 can still be improved when compared to about 20 times each time, because the number of data groups is small
Hdu2847
# Include <iostream> # include <stdio. h> # include <string. h> # include <math. h> # include <algorithm> # include <string> # include <queue> # include <stdlib. h> using namespace STD; # define n 100 char G [N]; int Len; int mcheck (int x) {char TMP [N]; int CNT = 0; while (x) {TMP [CNT ++] = x % 2 + '0'; X >>=1 ;}int tcnt = 0; For (INT I = cnt-1; I >= 0; I --) {If (G [tcnt] = TMP [I]) {tcnt ++; If (tcnt = Len) return 1 ;}} return 0;} int main () {wh Ile (scanf ("% s", g )! = EOF) {int K; Len = strlen (g); scanf ("% d", & K); If (G [0] = '0 ') {// if it is set to 0, it is still troublesome to printf ("0 \ n"); continue;} int ans =-1; for (INT I = K ;; I + = k) {If (mcheck (I) = 1) {ans = I; break;} int CNT = 0; int TMP [N]; while (ANS) {TMP [CNT ++] = ans % 2; ans >>=1 ;}for (INT I = cnt-1; I> = 0; I --) printf ("% d", TMP [I]); printf ("\ n");} return 0 ;}
Hdu2847 (violent)