Untitled

 avatar
user_5379400
plain_text
a year ago
943 B
6
Indexable
#include<iostream>
using namespace std;
const int mod = 1e9 + 7;

int n;
int a[15][5];

bool c;
int ans;

void dfs(int x, int y, int score){
  if (x == 0){
    ans = max(ans, score);
    return;
  }
  for (int i = -1; i <= 1; i++){
    int nx = x - 1;
    int ny = y + i;
    if (ny >= 0 && ny < 5){
      if (a[nx][ny] == 2){
        if (c){
          c = 0;
          dfs(nx, ny, score);
          c = 1;
        }
      }
      else {
        dfs(nx, ny, score + a[nx][ny]);
      }
    }
  }
}

void solve(int test){
  cin >> n;
  for (int i = 0; i < n; i++){
    for (int j = 0; j < 5; j++){
      cin >> a[i][j];
    }
  }
  ans = -1;
  c = 1;
  dfs(n, 2, 0);
  cout << "#" << test << ' ' << ans << '\n';

}

int32_t main(){
  //ios_base::sync_with_stdio(false), cin.tie(0);
  //freopen("file1.txt", "r", stdin);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) solve(i);


}
Editor is loading...
Leave a Comment