Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
733 B
2
Indexable
Never
#include<iostream>
using namespace std;
int ans=-1;
int dx[3]={-1,-1,-1};
int dy[3]={0,-1,1};
int N;
int a[100][100];
void chay(int r, int c, int p, int sum)
{

	if(r==0){
		if(ans<sum) 
		{
			ans=sum;
		}
		return ;
	}
	for(int i=0; i<3;i++){
		int x1= r+dx[i];
		int x2= c+dy[i];
		if( x1>=0 && x1<N && x2>=0 && x2<5){
			if(a[x1][x2]<2) chay(x1,x2,p,sum+a[x1][x2]);
			else if(p) chay(x1,x2,0,sum);
		}

	}

}
int main()
{
	//freopen("text.txt","r",stdin);
	int t;
	cin>>t;
	int sum=0;
	for(int tc=1; tc<=t;tc++){
		cin>>N;
		for(int i=0;i<N;i++){
			for(int j=0; j<5;j++){
				cin>>a[i][j];
			}
		}
		ans = -1;
		chay(N,2,1,0);
		cout<<"#"<<tc<< " "<<ans<<endl;
	}

	return 0;
}