167 - The Sultans Successors


Difficulty : easy

Solution Description :

Backtracking (8-queen problem)

At first find all possible combination of 8-queen using backtracking recursion and store all combination to array. You got 92 combination.

For each input find the maximum sum from all combination with given value.

For this combination
Solid white.svgabcdefghSolid white.svg
8 __ __ __ white queen __ __ __ __8
7 __ __ __ __ __ __ white queen __7
6 __ __ white queen __ __ __ __ __6
5 __ __ __ __ __ __ __ white queen5
4 __ white queen __ __ __ __ __ __4
3 __ __ __ __ white queen __ __ __3
2 white queen __ __ __ __ __ __ __2
1 __ __ __ __ __ white queen __ __1
Solid white.svgabcdefghSolid white.svg

 and for input 
                                   1  2  3  4  5  6  7  8
                                   9 10 11 12 13 14 15 16
                                  17 18 19 20 21 22 23 24
                                  25 26 27 28 29 30 31 32
                                  33 34 35 36 37 38 39 40
                                  41 42 43 44 45 46 47 48
                                  48 50 51 52 53 54 55 56
                                  57 58 59 60 61 62 63 64
Sum = 4 + 15 + 19 + 32 + 34 + 45 + 48 + 62 = 259