49392023-04-07 16:53:50TomaSajtDinamitcpp17Elfogadva 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];
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1832 KiB
2Elfogadva0/06ms2740 KiB
3Elfogadva2/23ms2496 KiB
4Elfogadva2/23ms2588 KiB
5Elfogadva3/33ms2552 KiB
6Elfogadva3/33ms2672 KiB
7Elfogadva2/26ms3244 KiB
8Elfogadva3/36ms3444 KiB
9Elfogadva2/23ms2864 KiB
10Elfogadva2/23ms2944 KiB
11Elfogadva3/33ms2864 KiB
12Elfogadva3/33ms3120 KiB
13Elfogadva2/23ms3144 KiB
14Elfogadva3/33ms3400 KiB
15Elfogadva2/26ms3820 KiB
16Elfogadva3/36ms3832 KiB
17Elfogadva2/26ms4096 KiB
18Elfogadva3/36ms3972 KiB
19Elfogadva2/26ms4224 KiB
20Elfogadva3/36ms4332 KiB
21Elfogadva2/26ms4204 KiB
22Elfogadva3/36ms4332 KiB