首先发现一点,设第(j)列被打掉的砖块个数为(k),那么第(j+1)列被打掉的砖块个数应该大于等于(k-1)
那么记(dp[j][i][k])表示第(j)列取了(i)个,总共取了(k)的最大分数,那么转移就是(dp[j][i][k]=max(dp[j+1][l][k-i])+sum_{t=1}^i a[t][j](lgeq i-1)),维护一下前缀和然后转移便是
//minamoto
#include<bits/stdc++.h>
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
inline int max(const int &x,const int &y){return x>y?x:y;}
inline int min(const int &x,const int &y){return x<y?x:y;}
using namespace std;
const int N=55;
int n,m,a[N][N],ans,f[N][N][N*N];
int main(){
// freopen("testdata.in","r",stdin);
scanf("%d%d",&n,&m);fp(i,1,n)fp(j,1,n-i+1)scanf("%d",&a[i][j]);
memset(f,0xef,sizeof(f));
f[n+1][0][0]=0;
fd(j,n,1)for(register int i=0,sum=0;i<=n-j+1;++i,sum+=a[i][j])fp(k,i,m)fp(l,max(i-1,0),n-j)
f[j][i][k]=max(f[j][i][k],f[j+1][l][k-i]+sum);
fp(i,1,n)fp(j,1,n-i+1)ans=max(ans,f[i][j][m]);
printf("%d
",ans);
}