AcWing 901. 滑雪
标签:size scan color str return scanf mes mem space
//f[i][j]表示从(i,j)开始滑的路径
#include
#include
#include
using namespace std;
const int N = 310;
int n, m;
int g[N][N];
int f[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int dp(int x, int y) {
int &v = f[x][y];
if (v != -1) return v;
v = 1;//加上*之后,这里等价f[x][y]=1; (引用)
for (int i = 0; i 4; i ++ ) {
int a = x + dx[i], b = y + dy[i];
if (a >= 1 && a = 1 && b g[a][b])
v = max(v, dp(a, b) + 1);
}
return v;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i )
for (int j = 1; j )
scanf("%d", &g[i][j]);
memset(f, -1, sizeof f);//表示每个状态都没算过
int res = 0;
for (int i = 1; i )
for (int j = 1; j )
res = max(res, dp(i, j));
printf("%d\n", res);
return 0;
}
AcWing 901. 滑雪
标签:size scan color str return scanf mes mem space
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/11906317.html
评论