Approach
Depth-first search
For CCC 1999 P3 - Divided Fractals, the implementation follows one branch at a time, making it suitable for components, trees, backtracking, or dependency exploration.
- Define the state carried into one recursive or stack frame.
- Mark or choose the current state before exploring children.
- Combine child results or undo the choice when the branch finishes.
Code notes
- 77 lines of Turing from the credited upstream file ccc99s3.t.
- The implementation keeps its working state in language-native values and containers.
- No explicit loop blocks detected.
Complexity
Count unique states for graph traversal; for backtracking, count the branching factor and maximum depth.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12345 678 9101112 13 14 15var infile : string := "frac.in"16var outfile : string := "frac.out"17var fi, fo : int18var count : int19var n, t, b, l, r : int20var s : array 1 .. 243, 1 .. 243 of string (1)21 2223242526procedure square (r : int, c : int, level : int)27 if level >= 1 then28 var n : int := 3 ** (level - 1)29 for i : r + n .. r + 2 * n - 130 for j : c + n .. c + 2 * n - 131 s (i, j) := " "32 end for33 end for34 square (r, c, level - 1)35 square (r, c + n, level - 1)36 square (r, c + 2 * n, level - 1)37 square (r + n, c, level - 1)38 square (r + n, c + 2 * n, level - 1)39 square (r + 2 * n, c, level - 1)40 square (r + 2 * n, c + n, level - 1)41 square (r + 2 * n, c + 2 * n, level - 1)42 end if43end square44 45open : fi, infile, get46open : fo, outfile, put47get : fi, count48for ii : 1 .. count49 get : fi, n50 get : fi, b51 get : fi, t52 get : fi, l53 get : fi, r54 var k : int := 3 ** n55 for i : 1 .. k56 for j : 1 .. k57 s (i, j) := "*"58 end for59 end for60 square (1, 1, n)61 for decreasing i : t .. b62 for j : l .. r63 put : fo, s (i, j), " " ..64 end for65 put : fo, ""66 end for67 put : fo, ""68end for69 70close : fi71close : fo72 73 74 75 76 77