王奕霏 @ 2018-12-06 14:35:17
#include<iostream>
using namespace std;
int height, lenth, mx=0;
int snow[110][110], dp[110][110];
void dfs(int x, int y){
if(x>0 && snow[x][y]<snow[x-1][y] && dp[x][y]+1>dp[x-1][y]){
dp[x-1][y]=dp[x][y]+1;
if(dp[x][y]+1>mx) mx=dp[x][y]+1;
dfs(x-1, y);
}
if(y>0 && snow[x][y]<snow[x][y-1] && dp[x][y]+1>dp[x][y-1]){
dp[x][y-1]=dp[x][y]+1;
if(dp[x][y]+1>mx) mx=dp[x][y]+1;
dfs(x, y-1);
}
if(x<lenth-1 && snow[x][y]<snow[x+1][y] && dp[x][y]+1>dp[x+1][y]){
dp[x+1][y]=dp[x][y]+1;
if(dp[x][y]+1>mx) mx=dp[x][y]+1;
dfs(x+1, y);
}
if(y<height-1 && snow[x][y]<snow[x][y+1] && dp[x][y]+1>dp[x][y+1]){
dp[x][y+1]=dp[x][y]+1;
if(dp[x][y]+1>mx) mx=dp[x][y]+1;
dfs(x, y+1);
}
}
int main(){
cin >> height >> lenth;
for(int i=0;i<height;i++){
for(int j=0;j<lenth;j++){
cin >> snow[i][j];
}
}
for(int i=0;i<height;i++){
for(int j=0;j<lenth;j++){
dfs(i, j);
}
}
cout << mx+1 << endl;/*
cout << endl << endl << endl << endl;
for(int i=0;i<height;i++){
for(int j=0;j<lenth;j++){
cout << dp[i][j] << " ";
}
cout << endl;
}*/
return 0;
}
by dbxxx @ 2018-12-06 15:46:51
错误WA掉的信息是啥?
by Qiuly @ 2018-12-06 16:36:07
看不懂你的代码,给你发篇题解看看,kruskal就行。你这个应该是考虑少了某个地方....
by Qiuly @ 2018-12-06 16:37:09
题解点这里
by Qiuly @ 2018-12-06 16:37:38
感觉dfs....