31 July

P1005 矩阵取数游戏

高精度不能更坑……

#include <cstdio>
#include <cstring>

struct INT {
	long long h, l;
};
long long t=1e18;
INT max(INT x, INT y) {
	if (x.h>y.h) return x; if (x.h<y.h) return y;
	if (x.l>y.l) return x; return y;
}
INT operator + (INT x, INT y) {
	INT res; res.l=x.l+y.l;
	res.h=x.h+y.h+res.l/t; res.l%=t;
	return res;
}
INT operator * (INT x, int y) {
	INT res; res.l=x.l*y;
	res.h=x.h*y + res.l/t; res.l%=t;
	return res;
}

int n, m;
long long G[83]; INT ans, f[83][83];

int main() {
	scanf("%d%d", &n, &m);
	while (n--) {
		for (int i=1; i<=m; ++i) scanf("%lld", &G[i]);
		memset(f, 0, sizeof(f));
		for (int j=0; j<m; ++j) for (int i=1; i+j<=m; ++i)
			f[i][i+j]=max(f[i+1][i+j] + (INT){0,G[i]}, f[i][i+j-1] + (INT){0,G[i+j]})*2;
		ans=ans+f[1][m];
	}
	if (ans.h) printf("%lld%018lld
", ans.h, ans.l);
	else printf("%lld
", ans.l);
	return 0;
}
原文地址:https://www.cnblogs.com/greyqz/p/11278220.html