Such a problem was given to me at my university, maybe someone will have an interesting algorithm on how to solve the problem. There are several solutions for this in stackoverflow, but none of them are suitable (because they are cyclically suitable for all possibilities).
Task: find all possible combinations for highlighting the given words in the given table, grid (rectangle, see below). There should not be free cells, and the word can be located from left to right or down. Words cannot be found by words after a word in a row (column).
Input: rectangular area, example:
+-----+ | * | | | +-----+
or
+-----+ | * | | | | *| | * | +-----+
Then after that, different words are typed (the following input data) to fill this grid, for example:
cdi zobxzst tdxic r sc zro and etc ...
The number is initially unknown, but is entered until the end of stdin - active EOF.
Output: if there is one solution, output this possible solution inside the filled grid. If no solution or number of solutions prints 0 or this is an exact number.
Example:
(entered table)
+-----+ | * | | | | *| | * | | * *| | * | | | +-----+
Then the words cdi zobxzst tdxic r sc zro rgfvacd oikf df x c r xvf ogish za sh fc hh h bfkh
(Each entry, but here is separated by spaces.)
Output (only 1 solution):
+-----+ |zro*h| |ogish| |bfkh*| |xvf*r| |za*c*| |sc*df| |tdxic| +-----+
Important note: the entered grid is limited to only 16 (!) Cells, the number of words is less than 60. I wrote an algorithm that looked through all possible combinations, but this did not work for me, because the execution time is limited (by 10 seconds, I think), and this the problem cannot be solved using a crude algorithm (for example, 15 on 15 grids and about 60 possible or more possible permutations that can be processed for about 1 day on a regular PC with a frequency of 2 GHz).
Perhaps there is another unique solution. Maybe this problem is more mathematical than programming, maybe you can use some left-right combinations in comparison with the upstream one? or perhaps suspended cells?
PS I have 3 weeks to solve this problem, if not, I can send the solution here after 3 weeks (good news);)