# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031657 | ezzzay | Raisins (IOI09_raisins) | C++14 | 378 ms | 53340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define int long long
const int N=52;
int a[N][N];
int dp[N][N][N][N];
int ps[N][N];
int fun(int y, int x, int a, int b){
if(dp[y][x][a][b]<INT_MAX)return dp[y][x][a][b] ;
if(y==a and x==b){
dp[y][x][a][b]=0;
return 0;
}
for(int i=y;i<a;i++){
int A= ps[a][b]-ps[a][x-1]-ps[y-1][b]+ps[y-1][x-1];
dp[y][x][a][b]= min(dp[y][x][a][b], A+fun(y,x,i,b)+fun(i+1,x,a,b) );
}
for(int i=x;i<b;i++){
int A=ps[a][b]-ps[a][x-1]-ps[y-1][b]+ps[y-1][x-1];
dp[y][x][a][b]= min(dp[y][x][a][b], A+fun(y,x,a,i)+fun(y,i+1,a,b));
}
return dp[y][x][a][b];
}
signed main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
for(int y=1;y<=n;y++){
for(int z=1;z<=m;z++){
dp[i][j][y][z]=INT_MAX;
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
ps[i][j]=ps[i][j-1]+ps[i-1][j]-ps[i-1][j-1]+a[i][j];
}
}
cout<<fun(1,1,n,m);
// cout<<dp[1][1][n][m];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |