#include <bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ick cout<<"ickbmi32.9\n"
using namespace std;
int mem[55][55][55][55];
int pre[55][55];
int arr[55][55];
int n,m;
int solve(int x1,int x2,int y1,int y2){
if(mem[x1][x2][y1][y2]!=0)return mem[x1][x2][y1][y2];
if(x1==x2&&y1==y2)return 0;
int a=999999999;
for(int i=x1;i<x2;i++)a=min(a,solve(x1,i,y1,y2)+solve(i+1,x2,y1,y2));
for(int i=y1;i<y2;i++)a=min(a,solve(x1,x2,y1,i)+solve(x1,x2,i+1,y2));
return mem[x1][x2][y1][y2]=a+pre[x2][y2]-pre[x2][y1-1]-pre[x1-1][y2]+pre[x1-1][y1-1];
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>arr[i][j];
pre[i][j]=arr[i][j]+pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
}
}
cout<<solve(1,n,1,m)<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
980 KB |
Output is correct |
8 |
Correct |
4 ms |
1868 KB |
Output is correct |
9 |
Correct |
7 ms |
2856 KB |
Output is correct |
10 |
Correct |
8 ms |
3284 KB |
Output is correct |
11 |
Correct |
10 ms |
2436 KB |
Output is correct |
12 |
Correct |
20 ms |
5864 KB |
Output is correct |
13 |
Correct |
34 ms |
7552 KB |
Output is correct |
14 |
Correct |
10 ms |
3012 KB |
Output is correct |
15 |
Correct |
45 ms |
8480 KB |
Output is correct |
16 |
Correct |
9 ms |
5152 KB |
Output is correct |
17 |
Correct |
21 ms |
7892 KB |
Output is correct |
18 |
Correct |
141 ms |
13760 KB |
Output is correct |
19 |
Correct |
175 ms |
14440 KB |
Output is correct |
20 |
Correct |
226 ms |
15544 KB |
Output is correct |