Banner Home Page Web Contests Problems Ranklist Status Statistics

Continuous Same Game (1)

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 87   Accepted Submission(s) : 23
Problem Description
Continuous Same Game is a simple game played on a grid of colored blocks. Groups of two or more connected (orthogonally, not diagonally) blocks that are the same color may be removed from the board. When a group of blocks is removed, the blocks above those removed ones fall down into the empty space. When an entire column of blocks is removed, all the columns to the right of that column shift to the left to fill the empty columns. Points are scored whenever a group of blocks is removed. The number of points per block increases as the group becomes bigger. When N blocks are removed, N*(N-1) points are scored. <br><br>LL was interested in this game at one time, but he found it is so difficult to find the optimal scheme. So he always play the game with a greedy strategy: choose the largest group to remove and if there are more than one largest group with equal number of blocks, choose the one which contains the most preceding block ( (x1,y1) is in front of (x2,y2) if and only if (x1&lt;x2 || x1==x2 &amp;&amp; y1&lt;y2) ). Now, he want to know how many points he will get. Can you help him?
 

Input
Each test case begins with two integers n,m ( 5<=n,m<=20 ), which is the size of the board. Then n lines follow, each contains m characters, indicating the color of the block. There are 5 colors, and each with equal probability.
 

Output
For each test case, output a single line containing the total point he will get with the greedy strategy. <br>
 

Sample Input
5 5<br>35552<br>31154<br>33222<br>21134<br>12314<br>
 

Sample Output
32<br><br><div style='font-family:Times New Roman;font-size:14px;background-color:F4FBFF;border:#B7CBFF 1px dashed;padding:6px'><div style='font-family:Arial;font-weight:bold;color:#7CA9ED;border-bottom:#B7CBFF 1px dashed'><i>Hint</i></div><br>35552 00552 00002 00002 00000 00000<br>31154 05154 05104 00004 00002 00000<br>33222 01222 01222 00122 00104 00100<br>21134 21134 21134 25234 25234 25230<br>12314 12314 12314 12314 12314 12312<br><br>The total point is 12+6+6+2+6=32.<br></div>
 

Statistic | Submit | Back