记录编号 176942 评测结果 AAAAAAAAAA
题目名称 [HNOI 2004] 打砖块 最终得分 100
用户昵称 Gravatar啊吧啦吧啦吧 是否通过 通过
代码语言 C 运行时间 0.357 s
提交时间 2015-08-10 15:03:46 内存使用 5.50 MiB
显示代码纯文本
#include <stdio.h>
#include <string.h>
#include <limits.h>

int f[52][52][502],a[51][51],b[51][51],sum[51][51],ans,l,j,k,i,n,m,nans;

main()
{
	FILE *fin, *fout;
	fin = fopen("brike.in", "r");
	fscanf(fin, "%d%d", &n, &m);
	ans = 0;
	for (i = 1; i <= n; ++i)
		for (j = 1; j <= n - i + 1; ++j)
			fscanf(fin, "%d", a[i] + j);
	fclose(fin);
	
	for (i = n; i > 0; --i)
		for (j = 1; j <= i; ++j){
			b[i][j] = a[j][i - j + 1];
			sum[i][j] = sum[i][j - 1] + b[i][j];
		}
	for (k = 1; k <= m; ++k)
		for (i = n; i > 0; --i)
			for (j = 0; j <= i; ++j)
				if (j <= k){
					nans = INT_MIN;
					for (l = j + 1; l >= 0; --l)
						if (l <= k - j)
							nans=f[i+1][l][k-j]>nans?f[i+1][l][k-j]:nans;
					f[i][j][k] = nans + sum[i][j];
					if (k == m && i == 1)
						ans = f[i][j][k] > ans ? f[i][j][k] : ans;
				}
	
	fout = fopen("brike.out", "w");
	fprintf(fout, "%d", ans);
	fclose(fout);
	return 0;
}