2
7
1 2 0 0 1
2 0 0 1 0
0 1 2 0 1
1 0 0 2 1
0 2 1 0 1
0 1 2 2 2
1 0 1 1 0
7
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
************************************
#include <iostream>
using namespace std;
#define SIZE 12
int data[SIZE][5];//
int N;//case的行数
int count;//最终钱币数
int tmp_count;
int mid;//飞机启示位置
void DFS(int step,int st){
if(step == N){
if(tmp_count>=count){
count = tmp_count;
}
if(tmp_count<0){
count = -1;
}
return;
}
int left = 0;//左右位置
int right = 0;
if(st == 0){
left = 0;
right = 1;
}
else if(st == 4){
left = 3;
right = 4;
}
else{
left = st-1;
right = st+1;
}
for(int k=left;k<=right;k++){//从左到右遍历三种情况
if(data[step][k] == 1){//碰到 1
tmp_count++;//钱币加 1
DFS(step+1,k);//叠代加 1
tmp_count--;//回朔
}
if(data[step][k] == 2){
tmp_count--;
DFS(step+1,k);
tmp_count++;
}
if(data[step][k] == 0){
DFS(step+1,k);
}
}
}
int main(int argc, char *argv[]){
freopen("input.txt","r",stdin);
int Case;
scanf("%d",&Case);
for(int i=0;i<Case;i++){
scanf("%d",&N);
count = 0;
for(int m=N-1;m>=0;m--){
for(int n=0;n<5;n++){
scanf("%d ",&data[m][n]);
}
}
count = 0;//初始化
tmp_count = 0;
mid = 2;
int tmp_data[12][5];//存储原始数据到中间数组
for(int i=0;i<N;i++){
for(int j=0;j<5;j++){
tmp_data[i][j] = data[i][j];
}
}
for(int q=0;q<N-5;q++){//遍历所有炸弹情况
for(int i=0;i<N;i++){//恢复原始数组
for(int j=0;j<5;j++){
data[i][j] = tmp_data[i][j];
}
}
for(int i=q;i<q+5;i++){//将5*5 区域中所有敌机消灭
for(int j=0;j<5;j++){
if(data[i][j] == 2){
data[i][j] =0;
}
}
}
DFS(0,mid);//叠代
}
//DFS(0,mid);
printf("%d\n",count);
}
return 1;
}