题意: 变形数塔
分析: 水题 - - 注意边界, 然后开大数组可以无视
代码:
//
// Created by TaoSama on 2015-10-27
// Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
typedef long long LL;
int n, a[205][205], dp[205][205];
void getMax(int &x, int y) {x = max(x, y);}
int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
int t; scanf("%d", &t);
int kase = 0;
while(t--) {
scanf("%d", &n);
memset(a, 0, sizeof a);
for(int i = 1, cnt = 0; i < n << 1; ++i) {
cnt += i <= n ? 1 : -1;
for(int j = 1; j <= cnt; ++j)
scanf("%d", &a[i][j]);
}
memset(dp, 0, sizeof dp);
for(int i = 1, cnt = 1; i < n << 1; ++i) {
int x = i <= n ? 1 : -1;
cnt += x;
for(int j = 1; j <= cnt; ++j) {
getMax(dp[i][j], dp[i - 1][j] + a[i][j]);
getMax(dp[i][j], dp[i - 1][j - x] + a[i][j]);
}
}
printf("Case %d: %d\n", ++kase, dp[(n << 1) - 1][1]);
}
return 0;
}