# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239361 | DavidDamian | Raisins (IOI09_raisins) | C++11 | 743 ms | 30188 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;
int n,m;
int A[55][55];
int sum[55][55];
int memo[55][55][55][55];
int getSum(int i,int j,int a,int b)
{
int total=sum[j][b]-sum[j][a-1]-sum[i-1][b]+sum[i-1][a-1];
return total;
}
int DivideConquer(int i,int j,int a,int b)
{
if(i==j && a==b)
return 0;
if(memo[i][j][a][b]==-1){
int minimum=INT_MAX;
for(int i_nxt=i;i_nxt<j;i_nxt++){
minimum=min(minimum,DivideConquer(i,i_nxt,a,b)
+DivideConquer(i_nxt+1,j,a,b)
+getSum(i,j,a,b));
}
for(int a_nxt=a;a_nxt<b;a_nxt++){
minimum=min(minimum,DivideConquer(i,j,a,a_nxt)
+DivideConquer(i,j,a_nxt+1,b)
+getSum(i,j,a,b));
}
memo[i][j][a][b]=minimum;
}
return memo[i][j][a][b];
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int a=1;a<=m;a++){
for(int b=1;b<=m;b++){
memo[i][j][a][b]=-1;
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>A[i][j];
sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+A[i][j];
}
}
int total=DivideConquer(1,n,1,m);
cout<<total<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |