9242022-01-28 13:40:17Valaki2Dinamitcpp14Accepted 50/504ms2688 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int inf = 1e9 + 7;

int n, m, k;
int h[41][41];
vector<vector<vector<int> > > dp;

void solve() {
    cin >> n >> m >> k;
    dp.assign(1 + n, vector<vector<int> > (1 + m, vector<int> (1 + k, inf)));
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> h[i][j];
        }
    }
    dp[0][1][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            int cur_h = h[i][j];
            for(int add = 0; add <= k; add++) {
                for(int ori = 0; ori + add <= k; ori++) {
                    dp[i][j][ori + add] = min({dp[i][j][ori + add], dp[i - 1][j][ori] + cur_h, dp[i][j - 1][ori] + cur_h});
                }
                cur_h /= 2;
            }
        }
    }
    cout << dp[n][m][k] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1844 KiB
2Accepted0/04ms2540 KiB
3Accepted2/22ms2016 KiB
4Accepted2/22ms2028 KiB
5Accepted3/32ms2048 KiB
6Accepted3/32ms2052 KiB
7Accepted2/24ms2548 KiB
8Accepted3/34ms2560 KiB
9Accepted2/22ms2020 KiB
10Accepted2/21ms2024 KiB
11Accepted3/31ms2028 KiB
12Accepted3/31ms2032 KiB
13Accepted2/22ms2108 KiB
14Accepted3/32ms2112 KiB
15Accepted2/24ms2596 KiB
16Accepted3/34ms2616 KiB
17Accepted2/24ms2620 KiB
18Accepted3/34ms2604 KiB
19Accepted2/24ms2616 KiB
20Accepted3/34ms2628 KiB
21Accepted2/24ms2672 KiB
22Accepted3/34ms2688 KiB