Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
48 kB
1
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#define MAX_SIZE 1000000
#define INF 10000000
using namespace std;
class Point{
public:
	int x;
	int y;
};
int Qx[MAX_SIZE], Qy[MAX_SIZE], front, rear;

void init(){
	front = rear = -1;
}

void push(int x, int y){
	rear++;
	Qx[rear] = x;
	Qy[rear] = y;
}

void pop(){
	front++;
}

int topX(){
	return Qx[front];
}

int topY(){
	return Qy[front];
}
bool isEmpty(){
	return front == rear;
}

int N, G;
int map[40][40] = {0};
Point postionGold[10] = {0};
int visited[100][100];
int vtHienTai[10] = {0};
int vtMin[10] = {0};
int minVt;
int numGold;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

void reset(){
	for(int i = 0; i <= N; ++i){
		for(int j = 0; j <= N; ++j){
			visited[i][j] = INF;
		}
	}
	for(int i = 0; i < 10; ++i){
		vtHienTai[i] = -1;
	}
}

void BFS(int x, int y){
	reset();
	init();
	push(x, y);
	visited[x][y] = 0;
	bool ch = false;
	while (!isEmpty())
	{
		pop();
		int xx = topX();
		int yy = topY();
		for(int i = 0; i < 4; ++i){
			int gx = xx + dx[i];
			int gy = yy + dy[i];
			if(gx >= 1 && gx <= N && gy >= 1 && gy <= N){
				if(map[gx][gy] == 1 && visited[xx][yy] + 1 < visited[gx][gy]){
					push(gx, gy);
					visited[gx][gy] = visited[xx][yy] + 1;
				}
				else if(map[gx][gy] >= 2 && visited[xx][yy] + 1 < visited[gx][gy]){
					push(gx, gy);
					visited[gx][gy] = visited[xx][yy] + 1;
					vtHienTai[map[gx][gy]-1] = visited[xx][yy] + 1;
					ch = true;
				}
			}
		}
	}
	if(ch == true){
		int numgGoldHt = 0;
		int maxHt = 0;
		for(int i = 1; i <= G; i++){
			if(vtHienTai[i] != -1){
				numgGoldHt++;
				if(vtHienTai[i] > maxHt){
					maxHt = vtHienTai[i];
				}
			}
		}
		if(numgGoldHt > numGold){
			numGold = numgGoldHt;
			minVt = maxHt;
			/*cout << "1NumgoldHt: " << numgGoldHt << " " << numGold 
				<< "MaxHt: " << maxHt << " " << minVt <<endl;*/ 
			for(int i = 1; i <= G; i++){
				vtMin[i] = vtHienTai[i];
			}
		}
		else if(numgGoldHt == numGold){
			/*cout << "2NumgoldHt: " << numgGoldHt << " " << numGold 
				<< "MaxHt: " << maxHt << " " << minVt <<endl;*/ 
			if(maxHt < minVt){
				minVt = maxHt;
				for(int i = 1; i <= G; i++){
					vtMin[i] = vtHienTai[i];
				}
			}
		}
	}
}

int main(){
	//freopen("input.txt", "r", stdin);
	int T;
	cin >> T;
	for(int tc = 1; tc <= T; ++tc){
		cin >> N >> G;
		for(int i = 1; i <= G; ++i){
			vtMin[i] = -1;
			cin >> postionGold[i].x >> postionGold[i].y;
		}
		for(int i = 1; i <= N; ++i){
			for(int j = 1; j <= N; ++j){
				cin >> map[i][j];
			}
		}
		numGold = 0;
		minVt = INF;
		for(int i = 1; i <= G; ++i){
			map[postionGold[i].x][postionGold[i].y] = i+1;
		}
		for(int i = 1; i <= N; ++i){
			for(int j = 1; j <= N; ++j){
				if(map[i][j] != 0){
					BFS(i, j);
				}
			}
		}
		if(numGold == 0){
			cout << "Case #" << tc << endl << -1 << endl;
		}
		else if(numGold < G){
			cout << "Case #" << tc << endl << minVt << endl;
			for(int i = 1; i <= G; i++){
				if(vtMin[i] == -1){
					cout << postionGold[i].x << " " << postionGold[i].y << endl;
				}
			}
		}
		else if(numGold == G){
			cout << "Case #" << tc << endl << minVt << endl;
		}
	}

	return 0;
}
50
5 2
4 3
3 4
1 1 0 0 0
1 1 0 0 0
1 1 1 1 1
1 1 1 0 1
1 1 1 1 1
8 2
5 6
6 4
1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 0
1 1 0 1 0 1 1 0
1 1 1 1 0 1 1 0
1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
10 3
8 2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0 1 1 1 1 
20 2
17 2
20 20
0 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 1 0 1 
1 0 1 1 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0 1 
0 1 1 1 1 0 1 1 0 1 0 0 0 1 0 0 1 1 1 0 
1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 
0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 
1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 1 1 0 0 1 
1 1 1 1 1 1 0 1 1 1 1 1 0 0 1 1 0 1 0 1 
1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 0 0 1 
1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 
1 1 0 0 0 1 1 1 1 1 1 0 1 0 1 0 0 0 1 1 
1 1 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 0 1 0 
0 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 
1 1 0 0 1 1 1 1 0 1 1 0 0 1 0 1 1 1 0 0 
0 0 1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1 0 
1 1 0 1 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 0 
1 0 1 0 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 
0 1 0 0 0 0 1 1 1 1 1 0 1 1 0 0 1 1 0 0 
0 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 
0 1 1 1 1 1 0 1 1 0 0 0 1 0 1 0 1 1 0 0 
0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 1
///
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#define MAX_SIZE 1000000
#define INF 10000000
using namespace std;

int N, L1, L2, L3, P1, P2, P3;
int timeAdv[5];
int pointAdv[5];
int khach[100][2];
int adv[10] = {0};
int minTime, maxTime;
bool visited[101];
int result;

void reset(){
	for(int i = 0; i < 100; ++i){
		visited[i] = false;
	}
}	

int tinhDiem(){
	int sum = 0;
	for(int i = 0; i < N; ++i){
		int point = 0;
		for(int j = 0; j < 3; ++j){
			if(khach[i][0] <= adv[j] && khach[i][0] + khach[i][1] >= adv[j] + timeAdv[j]){
				if(point < pointAdv[j]){
					point = pointAdv[j];
				}
			}
		}
		sum += point;
	}
	return sum;
}

void backtrack(int k){
	if(k==3){
		for(int i = 0; i < 3; ++i){
			for(int j = 0; j < 3; ++j){
				if(i != j){
					if(timeAdv[i] + adv[i] > adv[j] && 
						timeAdv[i] + adv[i] <= timeAdv[j] + adv[j])
					{
						return;
					}
				}
			}
		}
		int  n = tinhDiem();
		if(n > result){
			result = n;
		}
		return;
	}
	for(int i = 1; i <= 50; ++i){
		if(visited[i] == false){
			visited[i] = true;
			adv[k] = i;
			backtrack(k+1);
			adv[k] = 0;
			visited[i] = false;
		}

	}
}

int main(){
	freopen("input.txt", "r", stdin);
	int T;
	cin >> T;
	for(int tc = 1; tc <= T; ++tc){
		cin >> N;
		for(int i = 0; i < 3; ++i){
			cin >> timeAdv[i];
		}
		for(int i = 0; i < 3; ++i){
			cin >> pointAdv[i];
		}
		minTime = INF;
		maxTime = 0;
		for(int i = 0; i < N; ++i){
			cin >> khach[i][0] >> khach[i][1];
			if(khach[i][0] < minTime){
				minTime = khach[i][0];
			} 
			if(khach[i][1] > maxTime){
				maxTime = khach[i][1];
			}
		}
		reset();
		for(int i = 0; i < 5; ++i){
			adv[i] = 0;
		}
		result = 0;

		backtrack(0);

		cout << "Case #" << tc << endl << result << endl;
	}

	return 0;
}
50
7 1 2 3 1 2 3
2 2
6 4
3 3
7 2
1 1
2 1
1 10
4 3 2 1 6 4 3
1 5
1 3
2 4
2 2
3 1 2 3 7 6 4
10 1
11 2
13 3
5 2 2 1 2 5 4
2 4
4 6
9 1
14 10
30 15
50 31 4 1 734 134 546 
1 39
4 28
9 24
12 16
7 29
6 27
12 14
24 18
1 34
11 20
5 23
31 16
12 38
3 35
10 2
35 14
11 34
31 13
6 14
10 7
4 17
15 19
7 36
8 19
13 20
7 18
27 6
9 5
13 14
2 20
9 12
5 13
34 12
5 20
17 7
18 31
33 6
14 8
4 6
10 38
23 10
36 13
17 15
27 20
11 21
27 1
31 13
20 16
47 2
19 26
6 3 4 3 12 9 10
1 3
4 4
8 4
7 4
8 3
1 4
6 1 3 1 11 3 11
17 24
28 7
20 30
4 46
16 6
1 47
6 1 5 2 34 30 17
20 10
1 22
13 2
27 8
8 41
16 33
3 2 3 2 38 43 5
19 4
8 33
11 36
1 2 3 1 19 43 38
11 11
14 2 2 1 70 71 44
11 23
8 26
10 36
17 31
30 12
27 8
33 10
3 32
28 2
8 12
22 26
4 21
15 15
1 13
7 6 9 6 23 74 26
1 15
34 12
26 24
25 12
43 6
12 34
2 18
18 4 4 1 26 68 46
33 6
8 16
45 2
42 1
9 23
43 6
11 20
34 1
23 2
14 2
23 19
21 10
8 6
43 7
21 29
6 2
17 1
30 12
20 5 3 6 14 24 41
5 36
31 12
2 35
4 15
44 1
2 9
5 39
19 2
28 5
25 21
3 28
7 18
1 31
17 9
7 4
4 30
36 7
17 24
1 20
16 3
11 2 3 9 89 39 11
30 2
8 41
13 9
20 9
18 9
23 20
26 11
14 33
8 35
12 35
9 26
7 3 4 10 47 79 87
2 24
1 41
8 1
9 5
24 2
30 1
7 29
7 7 8 8 56 80 39
7 26
35 5
16 28
14 29
16 32
21 18
3 26
12 8 2 9 17 72 28
8 29
4 1
17 24
40 2
21 8
6 9
5 13
17 9
5 39
4 31
28 4
3 36
7 1 8 5 98 57 61
1 4
30 1
27 13
7 11
10 16
21 14
33 9
6 10 5 2 62 3 32
5 21
15 31
10 29
11 15
26 8
5 15
14 12 5 16 145 173 246
29 6
19 28
18 31
33 12
14 30
29 19
33 11
11 16
14 33
6 38
44 5
16 20
18 22
4 38
23 20 6 20 480 471 199
24 23
10 9
9 29
39 6
19 27
24 8
23 12
15 18
23 19
27 8
27 16
14 11
46 3
13 36
4 39
18 19
40 10
16 8
20 28
5 19
26 7
27 13
12 36
21 11 8 12 167 294 326
31 7
19 11
47 3
2 1
4 17
16 12
13 30
14 17
3 44
10 22
24 4
35 8
26 22
19 7
6 30
23 7
32 12
36 8
13 21
24 1
33 7
23 8 3 4 204 177 128
22 14
18 10
7 24
8 21
4 25
14 31
9 34
10 36
6 6
24 18
19 3
39 10
32 3
23 20
20 10
21 20
16 30
20 26
22 17
24 10
14 13
2 10
39 10
15 8 19 11 94 352 337
33 6
8 37
26 3
5 7
29 15
23 2
15 20
26 14
12 23
6 6
25 3
35 13
36 4
15 27
21 1
12 2 16 11 102 320 452
35 14
7 32
3 19
21 26
11 21
24 2
15 10
32 6
38 7
4 31
6 8
10 33
13 2 15 6 194 80 243
13 14
16 2
18 22
13 13
43 6
4 35
30 19
12 17
5 11
7 7
28 18
11 30
4 25
19 5 6 14 138 401 439
45 3
5 5
29 19
23 13
2 7
13 7
11 10
19 1
3 15
37 8
6 11
16 11
19 6
11 32
4 44
10 12
17 13
19 12
6 29
14 2 6 17 201 14 43
18 11
28 13
14 15
12 4
16 9
12 22
4 29
4 15
1 38
24 16
26 17
19 9
31 9
5 21
14 6 11 20 115 187 321
23 24
3 27
12 9
28 18
35 12
6 5
7 5
16 32
1 5
21 11
11 38
36 3
11 23
26 17
29 22 25 1 881 884 274
21 20
23 12
12 16
4 8
6 28
29 8
24 4
1 45
30 12
20 18
29 21
12 36
12 9
15 5
14 15
2 1
30 11
4 27
2 4
31 16
9 17
10 17
45 3
17 14
29 13
17 16
37 2
39 6
30 12
23 13 23 12 498 643 634
8 2
24 1
14 23
2 46
4 46
3 43
7 4
2 13
46 4
2 26
10 20
21 27
9 25
1 25
22 15
10 4
10 25
11 16
5 41
13 12
32 3
35 14
8 31
22 8 21 11 467 961 900
6 23
21 6
36 3
29 6
11 30
17 28
36 14
40 4
24 21
7 37
1 46
2 44
17 12
28 3
34 3
14 18
28 19
11 28
29 10
9 11
1 11
38 4
26 7 20 19 787 304 842
12 7
3 34
27 3
2 48
21 26
7 11
23 22
11 38
24 5
1 41
14 1
4 24
15 21
31 17
5 25
32 12
2 24
12 26
39 5
13 12
36 8
11 9
10 1
6 12
25 11
19 16
34 11 20 16 459 207 689
22 7
23 24
4 34
14 23
23 26
5 21
1 34
13 20
24 11
3 4
10 18
7 28
5 27
16 29
1 24
33 5
16 29
20 11
14 35
11 37
8 3
7 14
41 5
23 3
15 25
29 8
32 3
5 30
6 17
12 31
5 29
44 5
29 20
14 4
31 12 13 22 237 822 823
33 16
25 3
9 34
13 34
25 16
1 45
14 17
15 25
46 4
16 17
10 8
20 4
31 6
33 17
1 31
30 12
7 7
10 5
24 6
13 28
5 3
15 25
2 34
18 9
39 11
7 41
2 46
7 36
23 6
6 36
7 35
33 2 8 25 625 390 641
20 2
18 20
7 1
36 1
30 15
31 13
9 11
43 1
19 24
13 35
8 37
16 9
21 8
19 10
19 14
30 2
6 10
3 19
3 38
30 4
12 21
12 36
22 27
1 2
22 6
41 6
3 20
3 2
16 32
37 3
23 7
4 33
9 15
25 20 4 7 119 439 977
26 1
7 4
21 27
3 16
5 14
15 26
34 10
3 29
15 24
5 13
3 28
33 17
30 13
20 10
20 13
16 28
14 7
1 4
41 3
4 23
30 6
16 30
10 30
19 27
5 39
22 7 2 23 435 733 788
37 2
25 7
15 28
31 5
24 1
32 4
36 5
35 12
31 9
1 23
17 18
32 10
30 14
22 2
1 9
19 23
21 2
31 17
17 31
8 30
41 5
18 27
22 7 12 9 393 913 905
1 16
37 9
21 20
15 13
18 21
5 38
11 14
27 13
14 35
26 17
8 28
19 10
24 12
9 40
5 10
21 1
11 34
19 15
10 30
22 19
24 23
1 23
33 8 32 7 942 106 497
49 1
15 4
6 28
22 19
27 6
10 40
33 5
23 11
20 18
28 15
21 4
5 6
9 15
39 7
21 16
5 34
3 21
28 5
36 1
22 18
17 6
6 16
26 2
39 3
8 19
9 30
12 24
3 9
19 19
36 12
10 1
19 7
28 21
48 1 4 36 965 152 460
27 11
4 26
2 45
23 15
5 26
11 26
2 9
12 29
7 19
13 21
20 8
28 12
12 31
40 2
19 11
18 14
34 8
20 9
32 2
17 33
28 3
36 9
14 35
4 19
3 27
8 7
11 33
10 14
18 22
11 21
11 5
6 36
10 25
26 6
24 24
35 8
15 9
29 12
17 1
11 13
1 6
7 20
16 22
31 8
17 19
34 12
15 25
3 3
43 13 22 9 688 476 169
16 21
11 13
44 5
21 12
26 7
16 24
6 30
36 2
14 32
2 48
9 20
27 5
30 9
11 27
26 13
33 12
7 28
26 19
16 30
3 7
5 17
21 4
2 28
25 21
2 2
11 4
2 48
26 21
9 30
12 2
9 30
4 23
10 19
13 32
26 23
24 14
15 5
4 28
17 11
31 4
4 13
5 17
10 10
37 14 4 15 463 441 250
10 14
36 12
18 28
3 27
7 36
16 16
11 12
24 22
36 6
31 5
9 40
6 10
28 11
43 1
40 5
11 27
25 8
29 3
14 31
2 4
12 23
24 24
33 10
19 11
38 10
32 11
24 10
16 30
42 5
22 16
20 16
3 3
1 5
30 8
8 39
10 22
1 26
31 17 4 4 979 652 689
32 17
26 13
34 16
8 34
24 21
4 12
6 26
4 26
28 8
26 19
7 41
36 8
26 11
32 15
8 9
9 14
37 9
36 5
32 3
27 14
27 3
2 48
8 28
7 25
28 11
26 6
39 9
23 8
39 6
5 40
27 8
50 16 23 2 947 875 329
1 41
35 6
3 28
12 15
28 20
22 21
23 22
35 2
23 15
32 12
10 31
18 8
1 25
22 1
44 6
26 17
18 17
14 21
16 2
17 6
26 20
17 21
45 3
11 31
31 9
21 10
6 23
48 2
10 36
14 29
1 11
34 15
44 3
17 16
9 15
28 17
35 11
7 4
17 30
2 18
38 8
21 24
1 13
4 28
18 24
17 21
25 14
7 3
48 2
36 9
50 22 8 8 756 883 690
16 11
8 30
45 3
42 6
26 22
7 39
4 27
19 7
14 20
48 2
15 8
9 1
3 15
16 4
1 6
39 10
15 28
27 2
34 11
26 14
33 14
2 7
15 27
5 27
19 8
17 5
11 24
2 44
9 41
7 39
8 14
3 3
34 11
16 32
35 14
12 13
12 19
7 20
36 12
15 27
3 22
1 22
19 4
5 14
37 8
43 1
9 31
2 21
12 29
16 7
50 21 18 2 471 299 613
8 10
19 20
20 11
39 11
46 4
30 17
13 27
19 6
16 24
29 1
25 14
37 8
25 3
22 27
18 22
15 10
10 7
25 12
36 11
14 4
27 22
7 27
33 3
8 24
5 27
24 14
33 4
7 41
16 26
37 9
26 8
18 15
14 36
21 4
34 4
5 44
19 20
18 23
10 40
12 14
10 15
42 3
25 21
31 11
18 14
12 9
2 3
17 10
10 1
26 4
50 9 2 19 627 406 191
7 33
14 32
13 19
2 28
2 8
16 34
6 12
5 16
6 4
43 7
2 35
6 16
28 10
40 7
39 6
1 43
27 7
18 23
12 33
23 4
16 30
29 11
7 35
18 1
14 5
42 2
18 25
13 27
31 11
19 1
2 2
31 14
1 36
23 15
9 34
10 35
48 2
7 18
12 27
22 22
20 15
7 2
13 1
10 3
4 45
15 24
1 36
17 5
14 23
39 5
50 2 6 6 223 60 491
39 3
27 12
21 2
39 5
2 1
12 2
35 9
15 12
6 33
6 18
2 16
9 40
15 15
6 23
8 1
16 6
29 18
14 12
10 11
2 41
3 13
6 11
12 11
15 6
22 21
44 5
14 17
14 15
1 11
6 25
6 43
17 7
12 27
5 40
18 19
15 30
22 5
4 34
1 14
19 30
23 5
4 31
28 13
28 4
5 30
6 23
27 20
5 10
2 33
10 29
///
#include<iostream>
using namespace std;
int n, lengthA[3], pointA[3];
int visitor[50][2];
int point[50];
int choose[3];
int Answer, maxx;
int start[3];
void advertise(int k, int time, int maxx) {
	if (k == 3) {
		for (int i = 0; i < n; i++) {
			point[i] = 0;
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < n; j++) {
				if (visitor[j][0] <= start[i] && visitor[j][1] >= (start[i] + lengthA[choose[i]])) {
					if (point[j] < pointA[choose[i]]) {
						point[j] = pointA[choose[i]];
					}
				}
			}
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += point[i];
		}
		if (sum > Answer) {
			Answer = sum;
		}
		return;
	}
	for (int i = time; i <= maxx; i++) {
		start[k] = i;
		advertise(k + 1, i + lengthA[choose[k]], maxx);
	}
}

int main(int argc, char** argv)
{
	int test_case;
	int T;


	freopen("input.txt", "r", stdin);
	cin >> T;

	for(test_case = 1; test_case <= T; ++test_case)
	{
		Answer = maxx = 0;
		cin >> n;
		cin >> lengthA[0] >> lengthA[1] >> lengthA[2];
		cin >> pointA[0] >> pointA[1] >> pointA[2];
		for (int i = 0; i < n; i++) {
			cin >> visitor[i][0] >> visitor[i][1];
			visitor[i][1] += visitor[i][0];
			if (visitor[i][1] > maxx) {
				maxx = visitor[i][1];
			}
		}
		for (int i = 0 ; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (i != j && j != k && k != i) {
						choose[0] = i;
						choose[1] = j;
						choose[2] = k;
						advertise(0, 1, maxx);
					}
				}
			}
		}
		// Print the answer to standard output(screen).
		cout << "Case #" << test_case << endl << Answer << endl;
	}
	return 0;//Your program should return 0 on normal termination.
}

////
#include <iostream>
using namespace std;

int MangConBo[20];
int ans;
void backtracking(int k, int n, int sum, int t){
	if(sum > t){
		return;
	}
	if(k == n){
		if(sum > ans){
			ans = sum;
		}
		return;
	}
	for(int i = 0; i < 2; ++i){
		if(i==0){
 			backtracking(k+1, n, sum, t);
		}
		else{
			backtracking(k+1, n, sum + MangConBo[k], t);
		}

	}
	return;
}

int main(){
	freopen("input.txt", "r", stdin);
	int T;
	std::cin >> T;
	for(int tc = 1; tc <= 1; ++tc){
		int TaiTrongXe, SoBo;
		std::cin >> TaiTrongXe >> SoBo;
		for(int i = 0; i < SoBo; ++i){
			std::cin >> MangConBo[i];
		}
		ans = -1;
		backtracking(0, SoBo, 0, TaiTrongXe);
		std::cout << "#" << tc << " " << ans << std::endl; 
	}
	
	return 0;
}



/////
#include <iostream>
using namespace std;
int arr[1000];


int safe(int R, int C){
	for(int i = 0; i < R; ++i){
		if(arr[i] == C){
			return false;
		}
		if(i - arr[i] == (R - C)){
			return false;
		}
		if(arr[i]+i == (R + C)){
			return false;
		}
	}
	return true;
}
int ans = 0;

int board[65][65];

void backtrack(int k){
	if(k==8){
		int sum = 0;
		for(int i = 0; i < 8; ++i){
			sum += board[i][arr[i]];
		}
		if(ans < sum){
			ans = sum;
		}
		return;
	}
	for(int i = 0; i < 8; ++i){
		if(safe(k, i)){
			arr[k] = i;
			backtrack(k+1);
		}
	}
}


int main(){
	//freopen("input.txt", "r", stdin);
	int T;
	std::cin >> T;
	for(int tc = 1; tc <= T; ++tc){
		int K;
		std::cin >> K;
		std::cout << "Case #" << tc << endl;
		for(int i = 0; i < K; ++i){
			for(int j = 0; j < 8; ++j){
				for(int p = 0; p < 8; ++p){
					std::cin >> board[j][p];
				}
			}
			ans = 0;
			backtrack(0);
			cout << ans << endl;
		}

	}
	return 0;
}

//////////
#include <iostream>
using namespace std;

int cnt;

int arr[1000] = {0};
int N;
char options[] = {'_', '+', '-'};
int border;
bool isZero(){
	int sum = 0, num = 0, sign = 1;
	for(int i = 0; i < N*2-1; ++i){
		if(i%2 == 0){
			num = num * 10 + arr[i];
		}
		else{
			if(arr[i] == '_'){
				continue;
			}
			sum += num * sign;
			num = 0;
			sign = arr[i] == '+' ? 1: -1;
		}
	}
	sum += num * sign;

	return sum==0;
}

void backtracking(int pos){
	if(pos == ((N*2)-1)){
		if(isZero()){
			cnt++;
		}	
		return;
	}
	for(int i = 0; i < 3; ++i){
		arr[pos] = options[i];
		backtracking(pos+2);
	}
}

int main(){
	//freopen("input.txt","r", stdin);
	int T;
	std::cin >> T;
	for(int tc = 1; tc <= T; tc++){
		std::cin >> N;
		for(int i = 0; i < N; ++i){
			arr[i*2] = i+1;
		}
		cnt = 0;
		border = N*2 - 1;
		backtracking(1);
		std::cout << "#" << tc << " " << cnt << std::endl;
	}
	return 0;
}
///
#include <iostream>
using namespace std;

char board[5][5];

bool check(int R, int C){
	if(board[R][C] == 'X'){
		return false;
	}
	for(int i = C-1; i >=0; --i){
		if(board[R][i] == 'C'){
			return false;
		}
		else if(board[R][i] == 'X'){
			break;
		}
	}
	for(int i = R-1; i >= 0; i--){
		if(board[i][C] == 'C'){
			return false;
		}
		else if(board[i][C] == 'X'){
			break;
		}
	}
	return true;
}

int ans = 0;

void backtrack(int k, int N){
	if(k == N*N){
		int sum = 0;
		for(int i = 0; i < N; ++i){
			for(int j = 0; j < N; ++j){
				if(board[i][j] == 'C'){
					sum++;
				}
			}
		}
		if(ans < sum){
			ans = sum;
		}
		return;
	}	
	int R = k/N;
	int C = k%N;
	if(check(R, C)){
		for(int i = 0; i < 2; ++i){
			if(i == 0){
				backtrack(k+1, N);
			}
			else{
				board[R][C] = 'C';
				backtrack(k+1, N);
				board[R][C] = '.';
			}
		}
	}
	else{
		backtrack(k+1, N);
	}
}

int main(){
	//freopen("input.txt", "r", stdin);
	int T;
	std::cin >> T;
	for(int tc = 1; tc <= T; tc++){
		int N;
		std::cin >> N;
		for(int i = 0; i < N; ++i){
			std::cin >> board[i];
		}
		ans = 0;
		backtrack(0, N);
		std::cout << "Case #" << tc << "\n" << ans << std::endl; 
	}
	return 0;
}

////
#include<iostream>

using namespace std;

typedef struct
{
	int x,y;
}o_xy;

int N,M; // kick thuoc matran input
int Map[110][110]; // map input

o_xy Dirty[15]; // max 10 vet ban
int MapDistant[15][15]; // mang khoang cach cac diem
int indexDirty;
bool VisitedDirty[15];

o_xy Queue[100000];
int Qd[100000];
bool VisitedBFS[110][110] = {false};


int r =-1, f = -1;

void push(o_xy point, int d)
{
	r++;
	Queue[r].x = point.x;
	Queue[r].y = point.y;
	Qd[r] = d;
}

void pop(o_xy &point, int &d)
{
	f++;
	point.x = Queue[f].x;
	point.y = Queue[f].y;
	d = Qd[f];
}

int dx[4] = {0,-1,0,1};
int dy[4] = {-1,0,1,0};

void reset()
{
	r = f = -1;

	for(int i = 0; i< 110; i++)
	{
		for(int j =0; j< 110; j++)
		{
			VisitedBFS[i][j] = false;
		}
	}
}


int BFS(o_xy startPoint, o_xy endPoint)
{
	int d = 0;
	push(startPoint, d);
	VisitedBFS[startPoint.x][startPoint.y] = true;
	o_xy pre;

	while(r!=f)
	{
		pop(pre,d);

		for(int i =0; i< 4; i++)
		{
			o_xy next;
			next.x = pre.x + dx[i];
			next.y = pre.y + dy[i];
			if(next.x >= 0 && next.x <N && next.y >= 0 && next.y < M)
			{
				if(VisitedBFS[next.x][next.y] == false && next.x == endPoint.x && next.y == endPoint.y)
				{
					return d + 1;
				}
				if(VisitedBFS[next.x][next.y] == false && Map[next.x][next.y] != 2)
				{
					push(next,d+1);
					VisitedBFS[next.x][next.y] = true;
				}
			}
		}
	}
	return -1;
}

int sum;
int maxSum;

void backTrack(int k, int m)
{
	if (sum > maxSum) {
		return;
	}

	if(k == indexDirty)
	{
		if(sum < maxSum)
		{
			maxSum = sum;
		}
		return;
	}
	for(int i = 1; i <= indexDirty;i++)
	{
		if(!VisitedDirty[i])
		{
			VisitedDirty[i] = true;
			sum += MapDistant[m][i];
			backTrack(k+1,i);
			VisitedDirty[i] = false;
			sum -= MapDistant[m][i];
		}
	}
}


int main()
{
//	freopen("Text.txt","r",stdin);
	int T;
	cin>>T;

	for(int tc = 1; tc <= T; tc++)
	{
		cin>>N>>M;
		reset();
		o_xy startPoint; // diem bat dau
		indexDirty = 0;
		for(int i = 0; i< N; i++)
		{
			for(int j = 0; j< M; j++)
			{
				cin>>Map[i][j];
				if(Map[i][j] == 1)
				{
					++indexDirty;
					Dirty[indexDirty].x = i;
					Dirty[indexDirty].y = j;
				}
				if(Map[i][j] == 3)
				{
					Dirty[0].x = i;
					Dirty[0].y = j;
				}
			}
		}
			// BFS
		bool isFail = false;
			for(int i = 0; i <= indexDirty; i++)
			{
				for(int j = 0; j <= indexDirty; j++)
				{
					if(i == j)
					{
						MapDistant[i][j] = 0;
					}
					else
					{
						reset();
						int valueDistant = BFS(Dirty[i],Dirty[j]);
						if(valueDistant == -1)
						{
							indexDirty += 1;
							isFail = true;
						}
						MapDistant[i][j] = valueDistant;

					}
				}
			}
			// process backtrack
			
			cout<<"Case #"<<tc<<endl;
			if(isFail)
			{
				cout<<-1<<endl;
			}
			else
			{
				sum = 0;
				maxSum = 1000000000;
				backTrack(0,0);
				cout<<maxSum<<endl;
			}
		}
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#define INF 10000
#define MAX_SIZE 500000
using namespace std;
int Qx[MAX_SIZE], Qy[MAX_SIZE], Qcnt[MAX_SIZE], Qhuong[MAX_SIZE], front, rear;

void init(){
	front = rear = -1;
}

void push(int x, int y, int cnt, int huong){
	rear++;
	Qx[rear] = x;
	Qy[rear] = y;
	Qcnt[rear] = cnt;
	Qhuong[rear] = huong;
}

void pop(){
	front++;
}

int topX(){
	return Qx[front];
}

int topY(){
	return Qy[front];
}

int topCnt(){
	return Qcnt[front];
}

int topHuong(){
	return Qhuong[front];
}

bool isEmpty(){
	return front == rear;
}

class Point{
public:
	int x;
	int y;
};


char map[201][201];
int visited[201][201];
int N, M;


void reset(){
	for(int i = 0; i < M; ++i){
		for(int j = 0; j < N; ++j){
			visited[i][j] = INF;
			map[i][j] = 0;
		}
	}
}

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int mi;
void DFS(int x, int y, int endx, int endy, int cnt, int huong){
	init();
	push(x, y, cnt, huong);
	//visited[x][y] = true;
	while(!isEmpty()){
		pop();
		x = topX();
		y = topY();
		cnt = topCnt();
		huong = topHuong();
		for(int i = 0; i < 4; ++i){
			int gx = x + dx[i];
			int gy = y + dy[i];
			if(gx >= 0 && gx < M && gy >= 0 && gy < N){
				if(gx == endx && gy == endy){
					if(huong == i && cnt < visited[gx][gy]){
						visited[gx][gy] = cnt;
					}
					else if(huong != i && cnt +1 < visited[gx][gy]){
						visited[gx][gy] = cnt+1;
					}
					
				}

				else if(cnt < visited[gx][gy] && map[gx][gy] == '0'){
					if(huong == i){
						push(gx, gy, cnt, i); 
						visited[gx][gy] = cnt;
					}
					else{
						push(gx, gy, cnt + 1, i);
						visited[gx][gy] = cnt+1;
						
					}
				}
			}
		}
	}
	return;
}

int main(){
	freopen("input.txt", "r", stdin);
	int T;
	cin >> T;
	for(int tc = 1; tc <= T; ++tc){
		cin >> N >> M;
		//cout << N << " " << M << endl;
		int x = 0, y = 0, xx = 0, yy = 0;
		cin >> y >> x >> yy >> xx;
		--x;
		--y;
		--xx;
		--yy;
		//cout << x << " " << y << " " << xx << " " << yy << endl;

		/*start.x = --x;
		start.y = --y;
		endP.x = --xx;
		endP.y = --yy;*/
		reset();
		for(int i = 0; i < M; ++i){
			cin >> map[i];
		}
		mi = INF;
		
		DFS(x, y, xx, yy, -1, -1);
		/*for(int i = 0; i < M; ++i){
			for(int j = 0; j < N; ++j){
				cout << visited[i][j] << " ";
			}
			cout << endl;
		}*/
		if(mi > visited[xx][yy]){
			mi = visited[xx][yy];
		}
		if(mi == INF){
			cout << -1 << endl;
		}
		else cout << mi << endl;
	}
	return 0;
}

#include <iostream>
using namespace std;

int qx[10000000];
int qy[10000000];
int qd[10000];
int f;
int r;
int n,m;
void push(int x, int y ){
	r++;
	qx[r]=x;
	qy[r]=y;
//qd[r]=z;
}
void pop(int &x, int &y){
	f++;
	x=qx[f];
	y=qy[f];
	//dis=qd[f];
}

//int dx[8]={0,1,0,-1,-1,-1,1,1};
//int dy[8]={1,0,-1,0,-1,1,1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int a[500][500];
int map[100][100];
int vis[500][500];
int vis1[500][500];
int sx0, sy0;
void bfs0(int level){
	f=r=-1;
	for(int i=0; i<n;i++){
			for(int j=0; j<m; j++){
				if(i==0||i==n-1||j==0||j==m-1) {
					if(a[i][j]<=level){
						sx0=i;
						sy0=j;
						vis[i][j]=0;
						push(sx0,sy0);
					}
				}
			}
		}
	while(f!=r){
		pop(sx0,sy0);
		for(int i1=0; i1<4; i1++){
			int xx0=sx0+dx[i1];
			int yy0=sy0+dy[i1];
			if(xx0>=0&&xx0<n&&yy0>=0&&yy0<m){
				if(vis[xx0][yy0]==1&&a[xx0][yy0]<=level){
					push(xx0,yy0);
					vis[xx0][yy0]=0;
				}
			}
		}
	}
}	
int sx, sy;
bool bfs1(){
	f=r=-1;
	int v=0;
	for(int i=0; i<n;i++){
			for(int j=0; j<m; j++){
				if(vis[i][j]==1) {
					sx=i;
					sy=j;
					v=1;
					break;
				}
			}
			if(v==1) break;
		}
	push(sx,sy);
	vis[sx][sy]=0;
	while(f!=r){
		pop(sx,sy);
		for(int i=0; i<4; i++){
			int xx=sx+dx[i];
			int yy=sy+dy[i];
			if(xx>=0&&xx<n&&yy>=0&&yy<m){
				if(vis[xx][yy]==1){
					push(xx,yy);
					vis[xx][yy]=0;
				}
			}
		}
	}
	int sum=0;
	for(int i=0; i<n;i++){
		for(int j=0; j<m; j++){
			sum+=vis[i][j];
		}
	}
	if(sum!=0) return true;
	else return false;
}	

int kq;
int main(){
	//freopen("input.txt", "r", stdin);
	int t=0;
	while(1){
		t++;
		kq=0;
		cin>>n>>m;
		if(m==0&&n==0) break;
		cout<<"Case "<<t<<": ";
		for(int i=0; i<n;i++){
			for(int j=0; j<m; j++){
				cin>>a[i][j];
			}
		}
		int min=100000;
		int max=0;
		for(int i=0; i<n;i++){
			for(int j=0; j<m; j++){
				if(a[i][j]>max) max=a[i][j];
			}
		}
		for(int i=0; i<n;i++){
			for(int j=0; j<m; j++){
				if(i==0||i==n-1||j==0||j==m-1) {
					if(a[i][j]<min) min=a[i][j];
				}
			}
		}

		for(int i=min; i<max;i++){
			for(int i1=0; i1<n;i1++){
			for(int j=0; j<m; j++){
				vis[i1][j]=1;
			}
		}
			bfs0(i);
			if(bfs1()) {
				kq=i;
				break;
			}
		}
		if(kq==0) cout<<"Island never splits."<<endl;
		else cout<<"Island splits when ocean rises "<<kq<<" feet."<<endl;
	}
return 0;
}