7612022-01-09 16:19:23Babják PéterTáblatöréscpp11Accepted 50/5063ms15772 KiB
#include <bits/stdc++.h>
#define MAXN 31
using namespace std;
int a[MAXN][MAXN];
int f[MAXN][MAXN][MAXN][MAXN];
int dp[MAXN][MAXN][MAXN][MAXN];
//start 15:25
int n,m;
bool inco(int i,int j,int k,int l)
{
	if(i<0 || j<0 || k<0 || l<0)return 1;
	if(i>=n || j>=m || k>=n || l>=m)return 1;
	if(k<i || l<j)return 1;
	return 0;
}
int rek(int i,int j,int k,int l)
{
	if(inco(i,j,k,l))return 0;
	if(dp[i][j][k][l]!=0)return dp[i][j][k][l];
	int x,y,z,v;
	x=f[i][j][i][l]+min(min(rek(i+2,j,k,l),rek(i+1,j+1,k,l)),min(rek(i+1,j,k-1,l),rek(i+1,j,k,l-1)));
	y=f[i][j][k][j]+min(min(rek(i+1,j+1,k,l),rek(i,j+2,k,l)),min(rek(i,j+1,k-1,l),rek(i,j+1,k,l-1)));
	z=f[i][l][k][l]+min(min(rek(i+1,j,k,l-1),rek(i,j+1,k,l-1)),min(rek(i,j,k-1,l-1),rek(i,j,k,l-2)));
	v=f[k][j][k][l]+min(min(rek(i+1,j,k-1,l),rek(i,j+1,k-1,l)),min(rek(i,j,k-2,l),rek(i,j,k-1,l-1)));
	dp[i][j][k][l]=max(max(x,v),max(y,z));
	return dp[i][j][k][l];
}
int cnt(int x,int b,int c,int d)
{
	int sum=0;
	for(int i=x;i<=c;i++)
	{
		for(int j=b;j<=d;j++)
		{
			sum+=a[i][j];
		}
	}
	return sum;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	int sum=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			for(int k=0;k<n;k++)
			{
				for(int l=0;l<m;l++)
				{
					if(inco(i,j,k,l)==0)
					{
						f[i][j][k][l]=cnt(i,j,k,l);
					}
				}
			}
		}
	}
	int ans=rek(0,0,n-1,m-1);
	cout<<ans<<endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2092 KiB
2Accepted0/043ms13864 KiB
3Accepted2/22ms2160 KiB
4Accepted2/21ms2264 KiB
5Accepted1/11ms2000 KiB
6Accepted1/12ms3456 KiB
7Accepted1/12ms2524 KiB
8Accepted2/22ms3304 KiB
9Accepted3/33ms4076 KiB
10Accepted3/310ms7348 KiB
11Accepted3/321ms10380 KiB
12Accepted3/321ms10380 KiB
13Accepted4/443ms13976 KiB
14Accepted4/445ms13976 KiB
15Accepted4/461ms15764 KiB
16Accepted5/559ms15632 KiB
17Accepted5/561ms15768 KiB
18Accepted5/561ms15772 KiB
19Accepted1/161ms15644 KiB
20Accepted1/163ms15652 KiB