PBCWZCC @ 2018-08-19 19:20:39
我翻出了不知多久前做的这题的记录,看到代码有一处很不爽就顺手改掉了,没想到。。。
#include<bits/stdc++.h>
using namespace std;
int R,C;
int f[111][111];
int a[111][111];
int mx[5]={0,1,-1,0,0},my[5]={0,0,0,1,-1};
int maxlen=1;
void dfs(int x,int y,int len)
{
int nx,ny,nlen=len+1;
for(int i=1;i<=4;i++)
{
nx=x+mx[i];ny=y+my[i];
if(a[x][y]>a[nx][ny]/*#####*/ && f[nx][ny]<nlen && nx>=1 && nx<=R && ny>=1 && ny<=C)
{
f[nx][ny]=nlen;
maxlen=max(maxlen,nlen);
dfs(nx,ny,nlen);
}
}
}
int main()
{
memset(f,-1,sizeof(f));
// printf("1");return 0;//刷出答案案
scanf("%d%d",&R,&C);
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
{
scanf("%d",&a[i][j]);
// f[i][j]=1;
}
}
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
{
if(f[i][j]==-1)dfs(i,j,1);
}
}
printf("%d",maxlen);
return 0;
}
恰好
改了一处后:
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int R,C;
int f[111][111];
int a[111][111];
int mx[5]={0,1,-1,0,0},my[5]={0,0,0,1,-1};
int maxlen=1;
void dfs(int x,int y,int len)
{
int nx,ny,nlen=len+1;
for(int i=1;i<=4;i++)
{
nx=x+mx[i];ny=y+my[i];
if(a[x][y]>a[nx][ny]/*#####*/ && f[nx][ny]<nlen && nx>=1 && nx<=R && ny>=1 && ny<=C)
{
f[nx][ny]=nlen;
maxlen=max(maxlen,nlen);
dfs(nx,ny,nlen);
}
}
}
int main()
{
memset(f,-1,sizeof(f));
// printf("1");return 0;//刷出答案案
scanf("%d%d",&R,&C);
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
{
scanf("%d",&a[i][j]);
// f[i][j]=1;
}
}
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
{
if(f[i][j]==-1)dfs(i,j,1);
}
}
printf("%d",maxlen);
return 0;
}
by Camorgx @ 2018-08-19 19:23:25
如果开了O2优化呢
by 铁锤 @ 2018-08-19 19:24:25
@李云龙 对呀
by SeKong @ 2018-08-19 19:26:01
胡扯淡,库文件增加只会导致编译时间增长,跟你T不T有个毛关系。本来就在T的边缘,多刷几次A掉有什么稀奇的,下次我再交之前删几行注释,过了就说是注释害得我T了,滑稽。
by Ouyyx2002 @ 2018-08-19 19:27:12
说不定是评测机升级的锅
@PBCWZCC
by CYJian @ 2018-08-19 19:27:30
不啊我的就很好啊..
记录,全部0ms..
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n;
int m;
int res;
int h[N + 1][N + 1];
int f[N + 1][N + 1];
int DFS(int x, int y)
int k = 0;
if(f[x][y] > 1) return f[x][y];
if(h[x][y] > h[x + 1][y]) k = max(k, DFS(x + 1, y) + 1);
if(h[x][y] > h[x - 1][y]) k = max(k, DFS(x - 1, y) + 1);
if(h[x][y] > h[x][y + 1]) k = max(k, DFS(x, y + 1) + 1);
if(h[x][y] > h[x][y - 1]) k = max(k, DFS(x, y - 1) + 1);
return f[x][y] = max(f[x][y], k);
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) h[i][0] = h[i][m + 1] = 2e9;
for(int i = 1; i <= m; i++) h[0][i] = h[n + 1][i] = 2e9;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%d", &h[i][j]), f[i][j] = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
res = max(res, DFS(i, j));
printf("%d\n", res);
return 0;
}
by Camorgx @ 2018-08-19 19:27:33
@Skqliao 对偶
by 铁锤 @ 2018-08-19 19:27:37
@chen_zhe
by 铁锤 @ 2018-08-19 19:28:05
@kkksc03
by 铁锤 @ 2018-08-19 19:28:23
@lin_to_to
by 铁锤 @ 2018-08-19 19:28:59
刚才似乎有人爆粗口