49392023-04-07 16:53:50TomaSajtDinamitcpp17Accepted 50/506ms4332 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> board(n + 1, vector<int>(m + 1));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> board[i][j];
    }
  }

  // what is the min cost of getting to [i;j] with d dynamites
  vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(k + 1, INT_MAX / 2)));

  dp[1][1][0] = board[1][1];
  for (int d = 1; d <= k; d++)
    dp[1][1][d] = dp[1][1][d - 1] / 2;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int d = 0; d <= k; d++) {
        for (int dd = 0; dd <= d; dd++) {
          dp[i][j][d] = min(dp[i][j][d], (board[i][j] >> dd) + min(dp[i][j - 1][d - dd], dp[i - 1][j][d - dd]));
        }
      }
    }
  }
  cout << dp[n][m][k];
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1832 KiB
2Accepted0/06ms2740 KiB
3Accepted2/23ms2496 KiB
4Accepted2/23ms2588 KiB
5Accepted3/33ms2552 KiB
6Accepted3/33ms2672 KiB
7Accepted2/26ms3244 KiB
8Accepted3/36ms3444 KiB
9Accepted2/23ms2864 KiB
10Accepted2/23ms2944 KiB
11Accepted3/33ms2864 KiB
12Accepted3/33ms3120 KiB
13Accepted2/23ms3144 KiB
14Accepted3/33ms3400 KiB
15Accepted2/26ms3820 KiB
16Accepted3/36ms3832 KiB
17Accepted2/26ms4096 KiB
18Accepted3/36ms3972 KiB
19Accepted2/26ms4224 KiB
20Accepted3/36ms4332 KiB
21Accepted2/26ms4204 KiB
22Accepted3/36ms4332 KiB