#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int n,m;
int mymap[51][51];
int tmap[51][51];
void init(){
cin >> n >> m;
for(int i = 0; i < n; i++){
for(int j = 0; j < n-i; j++){
cin >> mymap[i][j];
}
}
}
void zhuanhua (){
for(int i = 0; i < n; i++){
for(int j = 0; j < n-i; j++){
tmap[j+i][i] = mymap[i][j];
}
}
}
int main(int argc, const char * argv[])
{
init();
zhuanhua();
int result = 0;
int dp[51][510][51];
memset(dp, -1, sizeof(dp));
for(int i = 0; i < n; i++) dp[i][1][1] = tmap[i][0];
dp[0][0][0] = 0;
int mysum[51][51];
memset(mysum, 0, sizeof(mysum));
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
if(j==0) mysum[i][j] = tmap[i][j];
else mysum[i][j] = mysum[i][j-1]+tmap[i][j];
}
}
for(int i = 1; i < n; i++){
for(int j = 0; j <= m; j++){
for(int k = 0; k <= i+1; k++){
if(k <= j){
for(int p = (k-1 < 0 ? 0 : k-1); p <= i; p++){
if(dp[i-1][j-k][p]!=-1){
int temp = dp[i-1][j-k][p] + (k>0 ? mysum[i][k-1] : 0);
if(dp[i][j][k] < temp) dp[i][j][k] = temp;
if(j==m) result = (result < dp[i][j][k] ? dp[i][j][k] : result);
}
}
}
}
}
}
cout << result << endl;
}
wiki 1257 打砖块
最新推荐文章于 2018-10-11 08:04:36 发布