社区讨论

MLE求调

P1434[SHOI2002] 滑雪参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m0td73n7
此快照首次捕获于
2024/09/08 17:21
2 年前
此快照最后确认于
2025/11/04 21:31
4 个月前
查看原帖
CPP
#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;
} 

回复

2 条回复,欢迎继续交流。

正在加载回复...