On a Boggle grid, one can draw words by starting at a square, and then adding letters by tracing a path through the grid, going up, down, left, right, or diagonally, so long as no square is visited twice.
Consider the square grid above. How many ways can you spell 'COMBINATORICS' in it?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
To get a significant speed up why not:
for(int i=0; i<7; i++) ans+=solve(i,0); ans = ans*2+solve(7,0); cout << ans << endl;
Hi great solution, i have mad this program especialy to solve this problem, check it out https://www.youtube.com/watch?v=dZ1rOGeiviA
As is so subtly hinted in the problem title, the solution can be derived in much the same way as Pascal's Triangle can be generated: by taking the sum of adjacent elements in the previous row.
Here, the 'rows' are the columns of the grid. We define the function n ( x , y ) to be the number of ways to reach the cell at row y , column x while spelling out 'COMBINATORICS'. We specify n ( x , y ) = 0 anywhere it is not otherwise defined. Thus, we get:
n ( 0 , y ) = 1 ∀ y ∈ { 0 . . . 1 2 }
n ( x , y ) = n ( x − 1 , y − 1 ) + n ( x − 1 , y ) + n ( x − 1 , y + 1 ) ∀ x ∈ { 1 . . . 1 2 } and ∀ y ∈ { 0 . . . 1 2 }
By computing and caching the values of n ( x , y ) one column at a time, from left to right, we only need to do 1 3 ∗ 1 3 = 1 6 9 calculations. The answer is then:
y = 0 ∑ 1 2 n ( 1 2 , y ) = 4 9 7 9 7 7 7
http://oeis.org/A081113
Write down the path matrix Q=
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The answer is the sum of all entry of Q 1 2
⎝ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎛ 1 5 5 1 1 2 6 3 2 4 2 9 9 6 4 2 7 0 1 6 2 0 2 4 0 1 2 8 0 4 6 8 5 3 3 0 8 0 1 1 4 3 3 4 0 7 7 1 2 1 2 6 3 2 4 4 5 4 7 5 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2 4 7 2 5 6 8 6 6 1 4 4 5 0 2 0 4 2 7 0 1 6 7 7 3 5 2 1 2 2 1 3 4 3 2 8 0 7 3 1 6 2 2 4 2 8 2 3 6 4 2 9 0 0 5 7 0 5 7 6 6 1 4 4 6 5 7 1 5 5 3 3 4 0 2 9 9 6 4 1 2 7 8 3 5 2 1 2 2 0 3 4 2 0 7 9 9 6 1 5 8 8 4 2 7 0 9 3 3 9 8 2 0 5 0 2 0 4 5 3 3 4 0 4 5 4 7 5 2 6 3 2 4 1 1 2 7 7 3 4 0 1 1 4 3 3 0 8 0 6 8 5 3 1 2 8 0 4 2 0 2 4 0 2 7 0 1 6 2 9 9 6 4 2 6 3 2 4 1 5 5 1 1 ⎠ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎞
My solution is purely mathematics, just use computer program to do matrix multiplication. It can be potentially extended to many class of counting problem,
Yes, the problem title is a hint. I solved the problem with a simple spreadsheet. It is just summing up the number of legal ways from the last column. The following shows the last column first. The second column the sum of the legal ways of first column and so on. The answer is the sum of the last column data.
1 2 5 13 35 96 267 750 2123 6046 17303 49721 143365
1 3 8 22 61 171 483 1373 3923 11257 32418 93644 271218
1 3 9 26 75 216 623 1800 5211 15115 43923 127853 372735
1 3 9 27 80 236 694 2038 5981 17551 51512 151238 444211
1 3 9 27 81 242 721 2143 6359 18846 55803 165120 488331
1 3 9 27 81 243 728 2178 6506 19406 57805 171973 511068
1 3 9 27 81 243 729 2185 6541 19553 58365 173975 517921
1 3 9 27 81 243 728 2178 6506 19406 57805 171973 511068
1 3 9 27 81 242 721 2143 6359 18846 55803 165120 488331
1 3 9 27 80 236 694 2038 5981 17551 51512 151238 444211
1 3 9 26 75 216 623 1800 5211 15115 43923 127853 372735
1 3 8 22 61 171 483 1373 3923 11257 32418 93644 271218
1 2 5 13 35 96 267 750 2123 6046 17303 49721 143365
4979777
Problem Loading...
Note Loading...
Set Loading...
A simple solution via Dynamic Programming: