求HACK
查看原帖
求HACK
755114
CD43楼主2022/8/19 15:11
#include <bits/stdc++.h>
using namespace std;
long long f[101][101],q;
long long r,t;
void dfs(int x,int y)
{
	q+=f[x][y];
//	cout<<x<<" "<<y<<endl;
	f[x][y]=0;
	if(x==r&&t==y)return ;
	if(f[x-1][y]==max(max(f[x-1][y],f[x][y-1]),max(f[x+1][y],f[x][y+1]))&&x-1>0){
		dfs(x-1,y);
		return;
	}
	if(f[x][y-1]==max(max(f[x-1][y],f[x][y-1]),max(f[x+1][y],f[x][y+1]))&&y-1>0){
		dfs(x,y-1);
		return ;
	}
	if(f[x+1][y]==max(max(f[x-1][y],f[x][y-1]),max(f[x+1][y],f[x][y+1]))&&x+1<=r){
		dfs(x+1,y);
		return ;
	}
	if(f[x][y+1]==max(max(f[x-1][y],f[x][y-1]),max(f[x+1][y],f[x][y+1]))&&y+1<=t){
		dfs(x,y+1);
		return ;
	}
	return;
}
int main(){
	std::ios::sync_with_stdio(false);//去同步优化
	cin.tie(0);//缓存优化 
	cout.tie(0);//缓存优化
    
    cin>>r>>t;
    for(int i=1;i<=r;i++)
    {
    	for(int j=1;j<=t;j++)cin>>f[i][j];
	}
	dfs(1,1);
	cout<<q;
    return 0;
}

RT

2022/8/19 15:11
加载中...