// Problem: 5634. IOI 2009 Raisins
// Contest: omegaUp
// URL: https://omegaup.com/arena/problem/IOI-2009-Raisins/
// Memory Limit: 63 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
const int INF=INT_MAX;
int A[52][52];
int memo[52][52][52][52];
int fr(int i1,int j1, int i2, int j2){
if(i1==i2 && j1==j2) return 0;
int minimo=INF;
for(int i=i1+1;i<=i2;i++){
minimo=min(fr(i1,j1,i-1,j2)+fr(i,j1,i2,j2),minimo);
}
for(int i=j1+1; i<=j2;i++){
minimo=min(fr(i1,j1,i2,i-1)+fr(i1,i,i2,j2),minimo);
}
return A[i2][j2]-A[i1-1][j2]-A[i2][j1-1]+A[i1-1][j1-1]+minimo;
}
int dp(int i1,int j1, int i2, int j2){
if(memo[i1][j1][i2][j2]!=-1) return memo[i1][j1][i2][j2];
if(i1==i2 && j1==j2)return 0;
int minimo=INF;
for(int i=i1+1;i<=i2;i++){
minimo=min(dp(i1,j1,i-1,j2)+dp(i,j1,i2,j2),minimo);
}
for(int i=j1+1; i<=j2;i++){
minimo=min(dp(i1,j1,i2,i-1)+dp(i1,i,i2,j2),minimo);
}
memo[i1][j1][i2][j2]=A[i2][j2]-A[i1-1][j2]-A[i2][j1-1]+A[i1-1][j1-1]+minimo;
return memo[i1][j1][i2][j2];
}
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>A[i][j];
A[i][j]+=A[i-1][j]+A[i][j-1]-A[i-1][j-1];
}
}
///cout<<fr(1,1,n,m)<<'\n';
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
for(int k=1;k<=n;k++){
for(int l=1;l<=m;l++){
memo[i][j][k][l]=-1;
}
}
}
}
cout<<dp(1,1,n,m)<<'\n';
return 0;
Compilation message
raisins.cpp: In function 'int main()':
raisins.cpp:60:10: error: expected '}' at end of input
60 | return 0;
| ^
raisins.cpp:40:11: note: to match this '{'
40 | int main(){
| ^