Jelly_Goat @ 2019-04-28 20:36:28
by Jelly_Goat @ 2019-04-28 20:36:44
#include <iostream>
#include <cstdio>
using namespace std;
const int dx[5]={0,1,-1,0,0};
const int dy[5]={0,0,0,1,-1};
int dp[1001][1001];
int map[1001][1001];
int n,m;
int dfs(int x,int y)
{
if (x<1||y<1||x>m||y>n)return 0;
if (dp[x][y])return dp[x][y];
dp[x][y]=1;
for (int i=1;i<=4;i++)
{
int nowx=x+dx[i],nowy=y+dy[i];
if (map[x][y]<map[nowx][nowy])
dp[x][y]=max(dp[x][y],dfs(nowx,nowy)+1);
}
return dp[x][y];
}
int main()
{
scanf("%d%d",&n,&m);
for (register int i=1;i<=n;i++)
{
for (register int j=1;j<=m;j++)
{
scanf("%d",&map[i][j]);
}
}
int ans=0;
for (register int i=1;i<=n;i++)
{
for (register int j=1;j<=m;j++)
{
ans=max(ans,dfs(i,j));
}
}
printf("%d\n",ans);
return 0;
}
by Hydrogen_Helium @ 2019-04-28 20:43:39
@Jelly_Goat
伪队长,只能帮你到这里了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[110][110],book[110][110];
int n,m;
int d[4][2]={1,0,0,1,-1,0,0,-1};
int dfs(int x,int y)
{
if(book[x][y]!=0)return book[x][y];
else
{
int ans=1;
for(int k=0;k<4;k++)
{
int temp;
int x1=x+d[k][0];
int y1=y+d[k][1];
if(x1>=0&&x1<n&&y1>=0&&y1<m&&a[x][y]>a[x1][y1]){
temp=dfs(x1,y1)+1;
if(temp>ans)ans=temp;
}
}
book[x][y]=ans;
return ans;
}
}
int main()
{
cin>>n>>m;
memset(book,0,sizeof(book));
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]);
int max_0=0;
for(int o=0;o<n;o++)
{
for(int w=0;w<m;w++)
{
max_0=max(max_0,dfs(o,w));
}
}
cout<<max_0;
return 0;
}
by Jelly_Goat @ 2019-04-28 20:53:21
@Hydrogen_Helium
您这是什么毒瘤神仙代码WA...
by Hydrogen_Helium @ 2019-04-28 20:54:45
很久之前写的了。。。 当时码风丑陋。。。还请见谅
by Cesare @ 2019-04-28 21:23:01
@Jelly_Goat 建议开 long long 。