教主的花园

【代码】

#include<bits/stdc++.h>

using namespace std;

const int N = 100100, mod = 987654321;

int n, v[N][4],f[N][4][2], ans = 0;


int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d%d%d", &v[i][1], &v[i][2], &v[i][3]);
	for(int p = 1; p <= 3; ++p) {
		memset(f, 0, sizeof f);
		f[1][p][0] = f[1][p][1] = v[1][p];
		for(int i = 2; i <= n; ++i) {
			f[i][1][0] = max(f[i - 1][2][1], f[i - 1][3][1]) + v[i][1];
			f[i][2][0] = f[i - 1][3][1] + v[i][2];
			f[i][2][1] = f[i - 1][1][0] + v[i][2];
			f[i][3][1] = max(f[i - 1][1][0], f[i - 1][2][0]) + v[i][3];
		}
		if(p == 1) 
			ans = max(ans, max(f[n][2][1], f[n][3][1]));
		if(p == 2)
			ans = max(ans, max(f[n][1][0], f[n][3][1]));
		if(p == 3)
			ans = max(ans, max(f[n][1][0], f[n][2][0]));
	}
	printf("%d\n", ans);
	return 0;
}
posted @ 2018-03-25 14:22  绍兴土匪  阅读(119)  评论(0编辑  收藏  举报