#include<bits/stdc++.h>
#define int long long
using namespace std;
int tab[51][51];
int memo[51][51][51][51];
int solve(int xmin,int xmax,int ymin,int ymax)
{
if(memo[xmin][xmax][ymin][ymax]!=-1)
return memo[xmin][xmax][ymin][ymax];
int ans=1000*50*51,cur=0;
for(int x=xmin;x<=xmax;x++)
{
for(int y=ymin;y<=ymax;y++)
cur+=tab[x][y];
}
if((xmax-xmin==1 && ymax-ymin==0)||(xmax-xmin==0 && ymax-ymin==1))
return cur;
for(int x=xmin+1;x<=xmax;x++)
ans=min(ans,solve(xmin,x-1,ymin,ymax)+solve(x,xmax,ymin,ymax)+cur);
for(int y=ymin+1;y<=ymax;y++)
ans=min(ans,solve(xmin,xmax,ymin,y-1)+solve(xmin,xmax,y,ymax)+cur);
memo[xmin][xmax][ymin][ymax]=ans;
return ans;
}
signed main()
{
memset(memo,-1,sizeof(memo));
int n,m;
cin>>n>>m;
for(int x=0;x<n;x++)
{
for(int y=0;y<m;y++)
cin>>tab[x][y];
}
cout<<solve(0,n-1,0,m-1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
53260 KB |
Output isn't correct |
2 |
Correct |
19 ms |
53192 KB |
Output is correct |
3 |
Incorrect |
19 ms |
53176 KB |
Output isn't correct |
4 |
Incorrect |
20 ms |
53224 KB |
Output isn't correct |
5 |
Incorrect |
19 ms |
53204 KB |
Output isn't correct |
6 |
Incorrect |
19 ms |
53164 KB |
Output isn't correct |
7 |
Incorrect |
20 ms |
53204 KB |
Output isn't correct |
8 |
Incorrect |
23 ms |
53144 KB |
Output isn't correct |
9 |
Incorrect |
25 ms |
53204 KB |
Output isn't correct |
10 |
Incorrect |
28 ms |
53236 KB |
Output isn't correct |
11 |
Incorrect |
27 ms |
53204 KB |
Output isn't correct |
12 |
Incorrect |
47 ms |
53208 KB |
Output isn't correct |
13 |
Incorrect |
67 ms |
53260 KB |
Output isn't correct |
14 |
Incorrect |
36 ms |
53420 KB |
Output isn't correct |
15 |
Incorrect |
79 ms |
53248 KB |
Output isn't correct |
16 |
Incorrect |
24 ms |
53204 KB |
Output isn't correct |
17 |
Incorrect |
42 ms |
53252 KB |
Output isn't correct |
18 |
Incorrect |
183 ms |
53264 KB |
Output isn't correct |
19 |
Incorrect |
327 ms |
53260 KB |
Output isn't correct |
20 |
Incorrect |
371 ms |
53268 KB |
Output isn't correct |