SPOJ KRECT problem: K-rectangle counting

Here is the spoj (krect) issue that states

Given the square of the square M * N. Each square contains the letter of the English alphabet ('A' .. 'Z').

The K-rectangle of the board is a rectangle whose sides are parallel to the sides of the board and contain exactly K different types of letters

For example, with this 4 * 3 board:

CED
CEB
CBC
DDA

The rectangle [(1,1), (2,2)] is a 2-rectangle of the board, as it contains two different letters: C and E.

For M, N, K and the M * N board. Determine how many K-rectangles are on the board.

Can you offer any solution? All ideas are welcome.

+3
source share
4

, , , 25502500 100x100. , , K K-, K K-.

0

, -, , O (n ^ 4) , . , , , K = 6, , 6. 2D- , .

1 x .....6
2 x ..3
3 x .2
4 x .2
5 x .2
6 x 1

K , , , , .

0

, :

  • N * M, (.. ), " ", ;
  • "" , " " , :
  • 1,2 , , .

50 * 50 * 100 ( ) + 100 * 100 * 2 (/ ) + 100 * 100 * 26 ( ) = 530 000 . , "" , 100 * 100 + 100 * 100 * 2 + 100 * 100 * 26 = 290 000 , .

0

All Articles