记录编号 373927 评测结果 AAAAAAAAAA
题目名称 [BYVoid S3] 艾萨拉的激流 最终得分 100
用户昵称 Gravatarconfoo 是否通过 通过
代码语言 C++ 运行时间 1.648 s
提交时间 2017-02-21 23:31:02 内存使用 77.35 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::max;
#define file(x) "azshara."#x
const int W = 1010, L = 10000;
typedef long long ll;
int n, m, a[L][W];
int f[L][W], ans;
int main() {
	freopen(file(in), "r", stdin);
	freopen(file(out), "w", stdout);
	memset(f, 0xc0 ,sizeof(f));
	scanf("%d%d", &m, &n);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
	for (int i = 1; i <= m; i++) f[1][i] = a[1][i];
	for (int i = 2; i <= n; i++) for (int j = 1; j <= m; j++) if (a[i][j] != -1)
		f[i][j] = max(f[i][j], max(f[i - 1][j], max(f[i - 1][j - 1], f[i - 1][j + 1])) + a[i][j]);
	for (int i = 1; i <= m; i++) ans = max(ans, f[n][i]);
	printf("%d", ans);
}