Link: here:
Ah !! I was given to the pitfalls in English .. It has been written for two days !! The meaning of the question is wrong !! After understanding it, make sure that the AC...
This is the game .. Everyone has played. An N * m square. 1-5 represents a small grid of five colors. Two or more small grids are automatically removed .. This person is stupid. He will only delete the largest number of items one by one. When the number is the same, take the one with the smaller I, and the one with the same I will take the one with the smaller J, if none of the above is available, move down .. When there is no vertical bar, move the right on the left (I thought it was left at first !!)... Then, each time n consecutive records are eliminated, the score is N * (n + 1 )... How many points does it end.
Analysis:
First, remove the number of cells with the same number as DFS .. The final judgment does not need to be moved down or right .. Then we can get it done.
Code:
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; const int maxn = 22; int dir [4] [2] = {1, 0 }, {-}, {}, {0,-1 }}; int n, m; char map [maxn] [maxn]; int vis [maxn] [maxn]; // mark whether or not to access each access, and access the nth block int maxnum [maxn * maxn]; // record the number of each marked block int Len; int S; // The row on the left starts void DFS (int x, int y, char CH, int num) {int NX, NY; For (INT I = 0; I <4; I ++) {Nx = x + dir [I] [0]; ny = Y + dir [I] [1]; if (Map [NX] [NY] = '0' | Map [NX] [NY]! = CH | Vis [NX] [NY]) continue; vis [NX] [NY] = num; maxnum [num] ++; DFS (NX, NY, CH, num) ;}} int main () {While (scanf ("% d", & N, & M )! = EOF) {memset (MAP, '0', sizeof (MAP); getchar (); S = 1; int I, j; for (I = 1; I <= N; I ++) {for (j = 1; j <= m; j ++) {char c = getchar (); map [I] [J] = C;} getchar ();} int ans = 0; while (true) {memset (VIS, 0, sizeof (VIS )); memset (maxnum, 0, sizeof (maxnum); Len = 1; for (I = 1; I <= N; I ++) for (j = s; j <= m; j ++) if (vis [I] [J] = 0 & map [I] [J]! = '0') {vis [I] [J] = Len; maxnum [Len] ++; DFS (I, j, map [I] [J], Len ); len ++;} int max = 0, IMAX = 0; for (I = 1; I <Len; I ++) if (maxnum [I]> MAX) max = maxnum [I], IMAX = I; If (max <= 1) break; ans + = max * max-Max; for (I = 1; I <= N; I ++) for (j = s; j <= m; j ++) if (vis [I] [J] = IMAX) for (int K = I; map [k] [J]! = '0'; k --) map [k] [J] = map [k-1] [J]; bool flag = true; while (FLAG) {int mark = 0; for (Int J = m; j> = s; j --) {flag = true; For (INT I = 1; I <= N; I ++) if (Map [I] [J]! = '0') Flag = false; If (FLAG) {mark = J; break ;}} if (FLAG) {for (I = 1; I <= N; I ++) for (int K = mark; k> = s; k --) map [I] [k] = map [I] [k-1]; s ++ ;} if (M <1 | S> = m) Flag = false ;}} printf ("% d \ n", ANS) ;}return 0 ;}
Sample input:
8 811223344551122334455112233445511223344551122334455112233445511229 91112223334445551112223334445551112223334445551112223334445551112223334445551112225 512345543211112222333123456 61122332223334444412211115552222222118 81234543212345321321452311354231123541351131354213135421231354132
Sample output:
6416244122120