algorithm for placing n objects in n places We have n objects to place in n locations, provided the following constrains
1 - All objects must be placed
2 - All places must be taken
3 - Each object can only be placed in certain locations (a subset of locations).
As an special example consider a 7x7 grid (see image link below), with 24 blue letters (A-X) in the periphery, and 24 available locations in the grid. Each letter can be place in a cell from corresponding row or column, and the letters at the corners can be placed in a cell from corresponding diagonal.
Is there any non-brute-force algorithm for this problem?
image link: http://snag.gy/lojaM.jpg
 A: This is an exact cover problem, and so can be solved using Knuth's Algorithm X.  This is the same class of problems that includes, for example, sudoku.
Specifically, the set being covered consists of all the locations and all the objects; the covering subsets each consist of a single location and an object which may be placed in that location.
The exact cover problem is, in general, NP-complete, and thus a polynomial-time solution generally cannot be guaranteed (unless it turns out that P = NP, at least). However, Algorithm X (when efficiently implemented) does tend to be pretty fast in practice; for example, the fastest sudoku solvers typically use some variation of it.
It's possible that there might be a more efficient way to solve your problem by exploiting its special structure.  I somewhat doubt it, though: even though your problem has some restrictions compared to the general exact cover problem (which allows arbitrary covering sets), it still seems general enough that it might well itself be NP-complete.  Then again, I could be wrong about that.
