제출 #440322

#제출 시각아이디문제언어결과실행 시간메모리
440322dxz05건포도 (IOI09_raisins)C++14
100 / 100
1604 ms59592 KiB
#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 timeMemoryGrader output
Fetching results...