比赛 20130923 评测结果 AAAAAWAAAW
题目名称 打砖块 最终得分 80
用户昵称 coastline>> 运行时间 0.166 s
代码语言 C++ 内存使用 30.91 MiB
提交时间 2015-10-12 21:07:44
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
 
using namespace std;

static const int maxn = 100; 
int total[maxn][maxn];
int a[maxn][maxn];
int f[maxn][maxn][maxn * 8];
int ans, n, m;

int qread(void) {
	int x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	return x;
}
 
int main() {
	freopen("brike.in", "r", stdin);
	freopen("brike.out", "w", stdout);
	
    n = qread(); m = qread();
    
    for(int i = 1; i <= n; ++i)
        for(int j=1;j<=n-i+1;++j)
            a[n - j + 1][i] = qread();
    
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= i; ++j)
            total[i][j] = total[i][j - 1] + a[i][j];
    
    for(int i = 0; i <= n; ++i)
        f[i][0][0] = 0;
    
    f[1][1][1] = a[1][1];
    for(int i = 2; i <= n; ++i)
        for(int j = 0; j <= i; ++j)
            for(int k = 0; k <= m; ++k)
                if(k >= j)
                    for(int p = j - 1; p <= i - 1; ++p)
                        if(f[i - 1][p][k - j] > 0)
                            if(f[i][j][k] < total[i][j] + f[i - 1][p][k - j]) {
                                f[i][j][k] = total[i][j] + f[i - 1][p][k - j];
                                ans = max(ans, f[i][j][k]);
                        	}
    
    printf("%d", ans);
    return 0;
}