The main topic: given two numbers n and M, if the number of length m satisfies for each I (n <= i <= m), the number of the first I bit can be divisible by I, then this number is the super number, to find the smallest dictionary order of the required super-number.
Problem-solving ideas: direct violence on the line, if every time to divide the judgment, the current number of each bit to take the remainder operation, then will time out, so every 18 bits to take the remainder (long Long data range is:-9223372036854775808). 9223372036854775807, so it can be AC at around 1S.
#include <cstdio>intN, M, a[ *];BOOLJudgeintCNT) {Long LongTMP =0; for(inti =0; I < CNT; ++i) {TMP = TMP *Ten+ A[i];if(i = = -) TMP%= CNT; }returntmp% CNT;}BOOLDFS (intcur) {if(cur = = m)return true; for(inti = cur?0:1; I <Ten; ++i) {A[cur] = i;if((Cur < n-1|| !judge (cur +1)) && DFS (cur +1))return true; }return false;}intMain () {intT, cnt =0;scanf("%d", &t); while(t--) {printf("Case%d:", ++cnt);scanf("%d%d", &n, &m);if(DFS (0)) { for(inti =0; I < m; ++i)printf("%d", A[i]);puts(""); }Else puts("-1"); }return 0;}
UVA-10624 Super Number