看到m<=2,果断乱搞。。然后搞着搞着自己被搞晕了233333
1 #include<bits/stdc++.h> 2 #define inc(i,l,r) for(i=l;i<=r;i++) 3 #define dec(i,l,r) for(i=l;i>=r;i--) 4 #define inf 1e9 5 #define ll long long 6 #define mem(a) memset(a,0,sizeof(a)) 7 using namespace std; 8 int n,m,p,i,j,k,c[105][15],a[105][3],f[105][105][15],ans,v,t; 9 int read(){ 10 int x=0,f=1;char ch=getchar(); 11 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 12 while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); 13 return x*f; 14 } 15 int main(){ 16 n=read();m=read();p=read(); 17 inc(i,1,n){ 18 inc(j,1,m) 19 a[i][j]=read(),a[i][j]+=a[i-1][j]; 20 } 21 if(m==1){ 22 inc(i,1,n)a[i][2]=-inf; 23 } 24 inc(i,0,n) 25 inc(j,0,n) 26 inc(k,0,p){ 27 inc(v,i+1,n){ 28 f[v][j][k]=max(f[v][j][k],f[i][j][k]); 29 f[v][j][k+1]=max(f[v][j][k+1],f[i][j][k]+a[v][1]-a[i][1]); 30 } 31 inc(v,j+1,n){ 32 f[i][v][k]=max(f[i][v][k],f[i][j][k]); 33 f[i][v][k+1]=max(f[i][v][k+1],f[i][j][k]+a[v][2]-a[j][2]); 34 } 35 t=max(i,j); 36 inc(v,t+1,n){ 37 f[v][v][k]=max(f[v][v][k],f[i][j][k]); 38 f[v][v][k+1]=max(f[v][v][k+1],f[i][j][k]+a[v][1]+a[v][2]-a[t][1]-a[t][2]); 39 } 40 } 41 inc(i,1,n) 42 inc(j,1,n) 43 inc(k,1,p) 44 ans=max(ans,f[i][j][k]); 45 printf("%d",ans); 46 return 0; 47 }