Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:12:01+00:00 2026-06-14T07:12:01+00:00

Such problem was given me at my university, maybe someone will have interesting algorithm

  • 0

Such problem was given me at my university, maybe someone will have interesting algorithm how to solve the problem. There’re several solutions for it on stackoverflow, but none of them is ok (because they’re looping for all possibilities).

Problem: Find all possible combinations for allocating given words into given table, grid ( rectangular, see input below ). There should be no free cells and word can be located from left to right or up to down. Words can’t be located word after word in a row (column).

Input: rectangular area, example:

+-----+
|  *  | 
|     |
+-----+

or

+-----+
|   * |
|     |
|    *|
|   * |
+-----+

Then after that different words are typed ( next input data ) to fill that grid such as:

cdi
zobxzst
tdxic
r
sc
zro
and etc ...

Number is initially unknown but inputs until end of stdin – active EOF.

Output: if one solution exists then output that possible solution within filled grid.
If no solution or number of solutions then output 0 or that exact number.

Example:

(table inputted)

+-----+
|   * |
|     |
|    *|
|   * |
|  * *|
|  *  |
|     |
+-----+

Then words cdi
zobxzst
tdxic
r
sc
zro
rgfvacd
oikf
df
x
c
r
xvf
ogish
za
sh
fc
hh
h
bfkh

(Each as input, but here separated by spaces.)

Output ( 1 solution only ):

+-----+
|zro*h|
|ogish|
|bfkh*|
|xvf*r|
|za*c*|
|sc*df|
|tdxic|
+-----+

Important note: The inputted grid is limited by 16 (!) cells only, number of words is less than 60. I wrote an algorithm which search through all possible combinations but it didn’t work for me as execution time is limited (by 10 sec I guess) and this problem couldn’t be solved with rough algorithm ( e.g. 15 on 15 grid and about 60! possible or more possible permutations which can be processed about 1 day? on ordinary 2GHz PC ).

Maybe there exists another unique solution. Maybe this problem is more mathematic then programming, maybe possible to use some left-right combos compared with up-down? or maybe weighted cells?

P.S. I have 3 weeks to solve that problem, if not, I can post solution here after 3 weeks ( good news ) 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:12:03+00:00Added an answer on June 14, 2026 at 7:12 am

    There’re several solutions for it on stackoverflow, but none of them is ok (because they’re looping for all possibilities).

    My idea is probably wrong as well then: but here’s an idea off the top of my head.

    I wrote an algorithm which search through all possible combinations

    If there are too many, then the problem is probably that you are also searching/looping through impossible combinations as well as possible combination.

    For example when you place a word like “zro” in the top-left corner, there are very few “possible” combinations which can be placed in the vertical words below it:

    1. the first vertical word must begin with ‘z’
    2. the second vertical word must begin with ‘r’
    3. the third vertical word must begin with ‘o’
    4. The combinations of letters on the second row (resulting from placing the vertical words) must itself be a valid word
    5. etc.

    Therefore:

    1. Pick any word and place it in the top-left corner
    2. Find existing words which satisfy the constraints above
    3. If you find one or more such words, then continue in this way to see whether you can solve the whole thing; or if you fail, then try again using a different initial word

    Summary:

    • Don’t generate every complete grid, and then test it to see whether it satisfies all constraints
    • Instead use the constraints as you build the grid, to reduce the number of possibilities that you test

    I’m suggesting that you solve the grid, starting from an initial word.

    Instead of testing each words in the top-left corner, a better (e.g. because it moe quickly eliminates impossibilities) way to generate the starting position[s] is:

    • Find the longest word (e.g. rgfvacd)
    • Find all possible combinations of words which cross/join it
    • Try to place each of those valid combinations on the grid
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have seen a few days ago such problem there is given two array
I need to solve such a problem. There is a base class and two
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I have to solve the following optimization problem: Given a set of elements (E1,E2,E3,E4,E5,E6)
I would like to know some solutions to such a problem. It is given
I have such problem: I'm using rails, devise gem and jQuery validation plugin. I
So, i have such problem: first time, then the <a> get clicked e.preventDefault() isn't
I have a problem such that i have zip files uploaded from forms and
What approach can I take to solve my problem such that my Android app
this must be such a simple problem but can someone tell me why this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.