# Untitled

unknown
plain_text
a year ago
1.2 kB
2
Indexable
Never
```#include<iostream>
using namespace std;

int a[25][5];

int X[3] = { 1,-1, 0};
int Y[3] = {-1,-1, -1};

int ans;
int n;

void Try(int row, int col, int bomb, int sum){
if(sum ==-1) return;
if(row ==0){
if (ans < sum )ans = sum;
return;
}
for(int h =0; h<3; h++){
int r = row +Y[h];
int c = col +X[h];

if(r >=0 && r<n && c>=0 && c<5){

if ( a[r][c] <2 ){
Try(r, c, bomb, sum + a[r][c]);
}
if (a[r][c] == 2){
if(bomb){
for(int i =r; i>r-5; i--){
for(int j =0; j<5; j++){
if(a[i][j] == 2) a[i][j] = 3;
}
}
Try(r,c,0,sum);
for(int i =r; i>r-5; i--){
for(int j =0; j<5; j++){
if(a[i][j] == 3) a[i][j] = 2;
}
}
}
else {
Try(r,c,0,sum-1);
}
}
if (a[r][c] == 3){
Try(r,c,0,sum);
}

}
}

}

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

for(int tc= 1; tc <= test; tc++){
cin >> n;

for(int i=0; i < n; i++){
for(int j= 0; j < 5; j++){
cin >> a[i][j];
}
}

ans =-1;
Try(n, 2, 1, 0);
cout << "Case #" << tc << endl;
cout << ans << endl;
}
return 0;
}
```