# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440322 | dxz05 | Raisins (IOI09_raisins) | C++14 | 1604 ms | 59592 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;
const int MAXN = 55;
int arr[55][55];
long long dp[55][55][55][55];
long long calc(int a, int b, int c, int d){
if (dp[a][b][c][d] != -1) return dp[a][b][c][d];
if (a == c && b == d) return dp[a][b][c][d] = 0;
if (a > c || b > d) return dp[a][b][c][d] = 2e9;
dp[a][b][c][d] = 2e9;
for (int i = a; i < c; i++){
dp[a][b][c][d] = min(dp[a][b][c][d], calc(a, b, i, d) + calc(i + 1, b, c, d));
}
for (int i = b; i < d; i++){
dp[a][b][c][d] = min(dp[a][b][c][d], calc(a, b, c, i) + calc(a, i + 1, c, d));
}
for (int i = a; i <= c; i++){
for (int j = b; j <= d; j++){
dp[a][b][c][d] += arr[i][j];
}
}
//cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << dp[a][b][c][d] << endl;
return dp[a][b][c][d];
}
int main(){
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> arr[i][j];
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
for (int ii = 1; ii <= n; ii++){
for (int jj = 1; jj <= m; jj++){
dp[i][j][ii][jj] = -1;
}
}
}
}
cout << calc(1, 1, n, m);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |