Eric2022 @ 2023-03-25 21:01:09
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
cin>>n>>m;
cout<<n*m;
return 0;
}
by Eric2022 @ 2023-03-25 21:11:38
@jiangshuhong 我们老师刚教的,没掌握,才来求助
by Eric2022 @ 2023-03-25 21:12:19
@Algae dfs,bfs会
by ryf_loser @ 2023-03-25 21:12:42
@Eric2022
int dfs(int x,int y){
if (w[x][y])return w[x][y];
w[x][y]=1;
for (int i=0;i<=4;i++){
int xx=x+sx[i];
int yy=y+sy[i];
if (xx>0&&yy>0&&xx<=r&&yy<=c&&a[x][y]>a[xx][yy]){
dfs(xx,yy);
w[x][y]=max(w[x][y],w[xx][yy]+1);
}
}
return w[x][y];
}
部分代码
by Eric2022 @ 2023-03-25 21:13:27
@ryf20100124 66666,谢谢大佬
by RNTBW @ 2023-03-25 21:16:36
不得不说,lz这么做在考场上是对的(bushi
by sad_lz @ 2023-03-25 21:22:32
lz真会写
by sad_lz @ 2023-03-25 21:23:15
#include<bits/stdc++.h>
using namespace std;
int r,c,a[105][105];
int main()
{
cin>>r>>c;
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
cin>>a[i][j];
}
cout<<25;
return 0;
}
试试
by _zyc_ @ 2023-03-25 21:31:57
#include<bits/stdc++.h>
using namespace std;
int n,a[1001][1001],dx[]={0,0,-1,1},dy[]={1,-1,0,0},f[1001][1001],m,ans;
int dfs(int x,int y)
{
if(f[x][y]!=-1)
{
return f[x][y];
}
f[x][y]=1;
for(int i=0;i<4;i++)
{
int xx=x+dx[i],yy=y+dy[i];
if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&a[x][y]>a[xx][yy])
{
dfs(xx,yy);
f[x][y]=max(f[x][y],f[xx][yy]+1);
}
}
return f[x][y];
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
f[i][j]=-1;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
ans=max(ans,dfs(i,j));
}
}
cout<<ans;
return 0;
}
by gnailuyiab @ 2023-08-14 23:02:31
不看你这代码我还真没发现样例有这规律,真是人才