P1434不过,MLE三个WA两个,求调
  • 板块灌水区
  • 楼主jjhjiangjunhao
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/9/8 17:23
  • 上次更新2024/9/8 20:31:23
查看原帖
P1434不过,MLE三个WA两个,求调
966108
jjhjiangjunhao楼主2024/9/8 17:23
#include<bits/stdc++.h>
using namespace std;
int List[101][101]={{0}},weight,height,Max=0,mx,my,ans[101][101]={0},mans=0;
void dfs(int x,int y){
	if(x<0 or x>=weight or y<0 or y>=height)return;
	if(List[x][y+1]<=List[x][y] and y+1<height and ans[x][y+1]<ans[x][y]+1){
		ans[x][y+1]=ans[x][y]+1;
		dfs(x,y+1);	
	}
	if(List[x+1][y]<=List[x][y] and x+1<weight and ans[x+1][y]<ans[x][y]+1){
		ans[x+1][y]=ans[x][y]+1;
		dfs(x+1,y);	
	}
	if(List[x][y-1]<=List[x][y] and y-1>=0 and ans[x][y-1]<ans[x][y]+1){
		ans[x][y-1]=ans[x][y]+1;
		dfs(x,y-1);
	}
	if(List[x-1][y]<=List[x][y] and x-1>=0 and ans[x-1][y]<ans[x][y]+1){
		ans[x-1][y]=ans[x][y]+1;
		dfs(x-1,y);	
	}
}
int main(){
	cin>>weight>>height;
	for(int i=0;i<weight;i++)for(int j=0;j<height;j++){
		cin>>List[i][j];
		if(List[i][j]>Max){
			Max=List[i][j];
			mx=i;
			my=j;
		}
	} 
	ans[mx][my]=1;
	dfs(mx,my);
	for(int i=0;i<weight;i++){
		for(int j=0;j<height;j++){
			mans=max(mans,ans[i][j]);
		}
	}
	cout<<mans;
	return 0;
} 

放在题目总版没人看
来流量最大的灌水区来看看有没有大佬调

2024/9/8 17:23
加载中...