206222026-01-07 22:21:35szabelrDinamitcpp17Accepted 50/506ms1184 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
long long dp[42][42][42];

const long long INF = 1e18;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, k;
    cin>>n>>m>>k;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            for (int y = 0; y <= k; y++) {
                dp[i][j][y] = INF;
            }
        }
    }
    dp[0][1][0] = 0;
    dp[1][0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int x; cin >> x;
            for (int curr_k = 0; curr_k <= k; curr_k++) {
                for (int d = 0; d <= curr_k; d++) {
                    int cost = x;
                    cost >>= d; 
                    long long prev_min = min(dp[i - 1][j][curr_k - d], dp[i][j - 1][curr_k - d]);

                    if (prev_min != INF) {
                        dp[i][j][curr_k] = min(dp[i][j][curr_k], prev_min + cost);
                    }
                }
            }
        }
    }
    cout << dp[n][m][k];
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms508 KiB
2Accepted0/06ms820 KiB
3Accepted2/22ms1184 KiB
4Accepted2/22ms820 KiB
5Accepted3/32ms836 KiB
6Accepted3/32ms820 KiB
7Accepted2/24ms968 KiB
8Accepted3/34ms996 KiB
9Accepted2/21ms332 KiB
10Accepted2/21ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/32ms316 KiB
13Accepted2/23ms564 KiB
14Accepted3/32ms564 KiB
15Accepted2/24ms820 KiB
16Accepted3/36ms820 KiB
17Accepted2/26ms820 KiB
18Accepted3/34ms996 KiB
19Accepted2/24ms820 KiB
20Accepted3/36ms824 KiB
21Accepted2/24ms1008 KiB
22Accepted3/34ms820 KiB