社区讨论
P1434不过,MLE三个WA两个,求调
灌水区参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @m0tdbj6t
- 此快照首次捕获于
- 2024/09/08 17:25 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;
}
放在题目总版没人看
来流量最大的灌水区来看看有没有大佬调
回复
共 1 条回复,欢迎继续交流。
正在加载回复...