关闭

ccc 2016 s4

53人阅读 评论(0) 收藏 举报
分类:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 400 + 5;
int n; int a[maxn]; int s[maxn];

void init() {
	scanf("%d", &n);
	for (int i = 0 ; i < n; i++) scanf("%d", &a[i]);
	s[0] = a[0];
	for (int i = 1; i < n; i++) s[i] = s[i - 1] + a[i];
}

int sum(int i, int j) {
	return s[j] - s[i] + a[i];
}

bool f[maxn][maxn];

void solve() {
	int ans = 0;
	memset(f, false, sizeof(f));
	for (int i = 0; i < n; i++) f[i][i] = true;
	
	for (int len = 1; len <= n; len ++ ) {
		for (int i = 0; i + len - 1 < n; i ++ ) {
			int j = i + len - 1;
			
			if (f[i][j]) { ans = max(ans, sum(i, j)); continue; }
			
			for (int k = i; k < j; k ++ ) {
				if (f[i][k] && f[k + 1][j] && sum(i, k) == sum(k + 1, j)) { f[i][j] = true; break; }
			}
			
			if (f[i][j]) { ans = max(ans, sum(i, j)); continue; }
			
			for (int len2 = 1; len2 <= len - 2; len2 ++ ) {
				if (f[i][j]) break;
				for (int k = i + 1; k + len2 <= j; k ++ ) {
					int t = k + len2 - 1;
					
					if (f[i][k - 1] && f[k][t] && f[t + 1][j] && sum(i, k - 1) == sum(t + 1, j)) {
						f[i][j] = true; break;
					}
				}
			}
			
			if (f[i][j]) ans = max(ans, sum(i, j));
		}
	}

	printf("%d\n", ans);
}

int main() {
	init(); solve();
	return 0;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:347次
    • 积分:52
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档