记录编号 |
317968 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[UVa 10285] 最长滑坡 |
最终得分 |
100 |
用户昵称 |
sxysxy |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.098 s |
提交时间 |
2016-10-08 19:09:42 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
class solve{
int *(*map);
int *(*val);
typedef int *pint;
int r, c;
public:
int get_num(){
int r;
char c;
while(!isdigit(c = getchar()));
r = c - '0';
while(isdigit(c = getchar()))r = r*10 + (c-'0');
return r;
}
pint *alloc2(int w, int h, bool zero = false){
pint *t;
t = new pint[w];
for(int i = 0; i < w; i++){
t[i] = new int[h];
if(zero)
memset(t[i], 0, h << 2);
}
return t;
}
void read(){
r = get_num();
c = get_num();
map = alloc2(r, c);
val = alloc2(r, c, true);
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
map[i][j] = get_num();
}
bool valid(int x, int y){
return !(x < 0 || y < 0 || x >= r || y >= c);
}
int calc(int x, int y){
if(!valid(x, y))return 0;
if(val[x][y])return val[x][y];
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {1, -1, 0, 0};
int &ans = val[x][y];
ans = 1;
for(int i = 0; i < 4; i++){
int nx = x + dx[i];
int ny = y + dy[i];
if(valid(nx, ny) && map[nx][ny] < map[x][y])
ans = max(ans, calc(nx, ny) + 1);
}
return ans;
}
void result(){
int ans = 0;
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
ans = max(ans, calc(i, j));
printf("%d\n", ans);
}
~solve(){
delete []val;
delete []map;
}
};
int main(){
freopen("shunzhi.in", "r", stdin);
freopen("shunzhi.out", "w", stdout);
solve solver;
solver.read();
solver.result();
return 0;
}