为什么只有70呢
查看原帖
为什么只有70呢
1267057
aa2211034566楼主2024/3/6 18:53
#include<bits/stdc++.h>
using namespace std;
int n,x,y,a[110][110],vist[110][110];
int sum=0;
int step;
int xx[]={1,-1,0,0};
int yy[]={0,0,-1,1};
void dfs(int h, int l, int ct) {
    sum = max(sum, ct);
    for (int i = 0; i < 4; i++) {
    	step=0;
        int dx = h;
        int dy = l;
        while(dx + xx[i] >= 1 && dx + xx[i] <= n && dy + yy[i] >= 1 && dy + yy[i] <= n) {
            	dx = dx + xx[i];
            	dy = dy + yy[i];
            	step++;
            	if(a[dx][dy]==0){
            		break;
				}
            }
        if (a[dx][dy]== 0 && vist[dx][dy]==0&&dx>=1&&dx<=n&&dy>=1&&dy<=n&&step!=1) {
            vist[dx][dy] = 1;
            ct=ct+step;
            dfs(dx, dy, ct);
            ct=ct-step;
            vist[dx][dy] = 0;
        }
    }
}


int main(){
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	vist[x][y]=1;
	dfs(x,y,0);
	cout<<sum;
	return 0;
}
2024/3/6 18:53
加载中...