Untitled

 avatar
unknown
plain_text
2 years ago
8.8 kB
16
Indexable
Sky Force
*** de bai 
There is an airplane game which to avoid enemies and gather coins.

The game's map has height is N and width is 5 (5 ≤ N ≤ 12), but due to the limit of the screen, the gaming zone is 5x5. Below the gaming zone, there is control zone, which is one line at the bottom of the screen where airplane move.

At the start of game, the airplane locates at center point of control zone.

Game rule :

         - Movement of airplane can be one of 3 options : left - right - stay at current column

         - In each turn, after airplane move, game map will move down one line

         - There is an option to use Bomb : bomb can be used to destroy all enemies in gaming zone, after used, all enemies will disappear and all coins will remain in the map. Bomb can be used only one.

         - When airplane meets a cell with coin, number of coins collected will increase by 1, if it meet an enemy, number of coins will decrease by 1. If number of coins < 0 -> Game Over.

Given the map Nx5 with C is value of each cell (0: nothing, 1: coin, 2:enemy), find out the maximum amount of coins can be achieved after finishing the game. If the game can not be finished (Game Over), return -1.

[Input]

The first line is the total number of test cases T ( T <= 50)

The first line of each test case contain N, which is the height of the map, then the N lines following descript the map's data.

[Output]

The maximum number of coins that can be collected after finishing the game.

If the game can not be finished, print -1.

*** Ex
Input

2

5

1 1 0 0 0

1 2 2 2 1

1 1 2 2 1

2 2 2 1 2

2 2 0 2 0

8

2 0 2 0 2

1 0 1 2 0

0 0 0 2 1

2 0 2 0 1

1 2 1 2 0

0 2 2 0 2

2 1 1 2 2

0 2 1 2 0

 

Output

Case #1

3

Case #2

4
*** test case
50
7
2 1 2 2 0
0 2 2 0 0
2 0 2 1 0
0 0 2 1 2
0 2 1 0 2
1 2 1 0 2
1 1 2 0 2
5
0 0 1 0 0
1 2 1 0 2
2 2 0 0 1
2 1 2 1 0
2 1 2 0 2
9
2 2 2 2 2
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
2 2 2 2 0
6
2 2 2 2 2
0 0 0 0 0
0 0 2 0 0
2 0 0 0 2
0 0 0 0 0
1 2 2 2 1
10
1 0 1 0 1
2 2 2 2 1
0 2 2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 1 0
0 2 1 0 2
2 0 0 0 1
0 0 2 2 0
1 2 1 0 2
0 1 1 1 1
1 2 1 2 1
2 0 0 1 2
9
1 2 1 0 2
2 2 2 1 1
2 1 1 2 1
1 2 1 0 2
1 2 1 1 0
1 1 1 2 2
0 1 0 2 0
0 0 0 0 0
1 2 0 0 1
8
2 2 0 0 1
2 1 2 2 1
0 0 0 1 1
0 2 1 1 0
0 2 2 1 1
1 0 0 0 2
2 1 2 2 1
1 1 2 0 0
*** output
Case #1
6
Case #2
4
Case #3
0
Case #4
-1
Case #5
8
Case #6
5
Case #7
5
Case #8
6
Case #9
10
Case #10
9
Case #11
3
Case #12
10
Case #13
9
Case #14
5
Case #15
8
Case #16
-1
Case #17
9
Case #18
8
Case #19
7
Case #20
7
Case #21
7
Case #22
7
Case #23
6
Case #24
5
Case #25
4
Case #26
5
Case #27
5
Case #28
9
Case #29
6
Case #30
5
Case #31
4
Case #32
6
Case #33
6
Case #34
6
Case #35
9
Case #36
10
Case #37
8
Case #38
8
Case #39
8
Case #40
5
Case #41
10
Case #42
8
Case #43
8
Case #44
6
Case #45
10
Case #46
7
Case #47
5
Case #48
6
Case #49
7
Case #50
7
*** code
#include<iostream>
using namespace std;
int N;
int map[15][5];
int mapCopy[15][5];
int ans;

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

void resetMapCopy(){
	for (int i = 0; i < N; i++){
		for ( int j = 0; j < 5; j++){
			mapCopy[i][j] = map[i][j];
		}
	}
}

void Try(int x, int y, int sum){
	if (x == 0) {
		if (ans < sum && sum >= 0) ans = sum;
		return;
	}

	for (int i = 0; i < 3; i++){
		int x1 = x + dx[i];
		int y1 = y + dy[i];

		if (x1>=0 && x1<N && y1>=0 && y1<5){
			sum += mapCopy[x1][y1];
			Try(x1, y1, sum);
			sum -= mapCopy[x1][y1];
		}
	}
}

void print(int x){
	if (x == 0){
		cout << "map Init" << endl;
		for (int i = 0; i < N; i++){
			for (int j = 0; j < 5; j++){
				cout << map[i][j] << " ";
			}
			cout << endl;
		}	
	}
	else if (x==1){
		cout << "map Copy" << endl;
		for (int i = 0; i < N; i++){
			for (int j = 0; j < 5; j++){
				cout << mapCopy[i][j] << " ";
			}
			cout << endl;
		}	
	}
}

int main(){
	freopen("input.txt","r",stdin);
	int TC; cin >> TC;
	for (int tc = 1; tc <= TC; tc++){
		cin >> N;
		for (int i = 0; i < N; i++){
			for ( int j = 0; j < 5; j++){
				cin >> map[i][j];
				if (map[i][j] == 2) map[i][j] = -1;
			}
		}
		//print(0);

		ans = -1;
		// tha bom
		if (N == 5) {
			resetMapCopy();
			for (int i = 0; i < 5; i++){
				for (int j = 0; j < 5; j++){
					if (mapCopy[i][j] == -1) mapCopy[i][j] = 0;
				}
			}
			Try(N, 2, 0);
			//print(1);
		}
		else {
			for (int k = 0; k <= N-5; k++){
				resetMapCopy();
				// no
				for (int i = k; i < k+5; i++){
					for (int j = 0; j < 5; j++){
						if (mapCopy[i][j] == -1) mapCopy[i][j] = 0;
					}
				}
				Try(N, 2, 0);
				//print(1);
			}
		}

		cout << "Case #" << tc << endl;
		if (ans < 0) cout << -1 << endl;
		else cout << ans << endl;
	}
	return 0;
}
Editor is loading...