#include"lib.h" #define fo(x,y) rep(x,y,a,b,p,lon) fc fi; int mot[1000000], code[1000], mot2[1000000]; int i, j, s, k, size = 3, x, nb, mnb, pos, a_o, a_i, lim = 20, p = 1, a, b, lon; int ok(){ if(mnb < nb) {printf("nb=%d", mnb = nb);date("");} for(k = 0; k < size; k++) if(mot[k+(nb-2)*size] > mot[k+(nb-1)*size]) break; else if(mot[k+(nb-2)*size] < mot[k+(nb-1)*size]){ i -= size; return 0;}//*/ for(*code = x = 0; ;) if(!fi(code, x)){ ici: while(code[x] == nb-1) if(!x--) return 1; code[x]++; }else{ s = nb-1-code[x];//optimized version //s = code[x];//old version for(k = 0; k < size; k++){ mot2[pos = k+x*size] = mot[k+s*size]; if(x && !(fo(mot2, pos))) return 0; } if(x == lim-1) goto ici; else code[++x] = 0; } } int other(){ if(i >= size) for(k = i-i%size; k <= i; k++) if(mot[k] < mot[k-size]) break; else if(mot[k] > mot[k-size]){ i -= i%size+1; return 0; }//*/ for(k = 0; k <= i%size; k++) mot2[size+k]=mot[i-i%size+k]; for(k = 0; k < i/size-1; k++){ for(j = 0; j < size; j++) mot2[j]=mot[k*size+j]; if(!fo(mot2, size+i%size)) return 0; } return 1; } int A(){ for(i = 0; i < size; i++) mot[i] = 0; mnb = nb = 0; printf("size=%d R(%d,%d) a_i=%d a/b=%d/%d+%d lim=%d", size, a_o, lon, a_i, a, b, p, lim); date(""); for(*mot = i = 0; ;) if(!(fo(mot, i)) || !other()){ here: while(mot[i] == a_o-1) if(!--i) return 1; //if(nb && i < 30) return 1;//optimisation au cas par cas mot[i]++; }else if((!((i+1)%size)) && ((nb = (i+1)/size) > 1)) if(!ok()) goto here; else if(nb == a_i) break; else goto there; else there: mot[++i] = 0; for(x = 0; x < a_i; x++, printf("\n")) for(k = 0; k < size; k++) printf("%d", mot[k+x*size]); printf("OK size=%d lim=%d", size, lim); date(""); return 0; } void usage(){ printf("Usage:gg a_o lon a_i a b plus [[size] lim]\n"); exit(0); } int main(int ac, char **av){ if(ac < 7) usage(); a_o = atoi(av[1]); lon = atoi(av[2]); a_i = atoi(av[3]); a = atoi(av[4]); b = atoi(av[5]); p = atoi(av[6]); if(ac > 7) size = atoi(av[7]); if(ac > 8) lim = atoi(av[8]); if(a_i == 3) fi = rt3; if(a_i == 4) fi = rt4; if(a_i == 5) fi = rt5; if(a_i == 6) fi = rt6; for(; A() /*&& size < 300*/; size++); } /* size=11 R(4,2) a_i=5 a/b=4/3+1 lim=15: 17/07/2007 15/03/47 nb=2: 17/07/2007 15/03/47 nb=3: 17/07/2007 15/03/47 nb=4: 17/07/2007 15/03/48 nb=5: 17/07/2007 15/03/50 00311201321 00231221132 00223113322 00123102133 00112233213 OK size=11 lim=15: 17/07/2007 15/04/02 */