107892024-04-12 19:48:00MagyarKendeSZLGFestés (50 pont)cpp17Accepted 50/50287ms67684 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vec vector
int N, M;

ll solve(const vector<bool>& mask, const vec<vec<ll>>& col) {
    vec<ll> dp(N + 1, LLONG_MAX);
    dp[0] = 0;
    for (int i = 1; i <= N; i++) {
        if (mask[i - 1]) {
            dp[i] = dp[i - 1];
        }
        for (int j = 0; j < i; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i] = min(dp[i], dp[j] + col[k][i - 1]);
            }
        }
    }
    return dp[N];
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> N >> M;
    vec<ll> rowS(N);
    vec<vec<vec<ll>>> colS(M, vec<vec<ll>>(N, vec<ll>(N)));

    for (int i = 0; i < N; i++) {
        cin >> rowS[i];
    }
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = j; k < N; k++) {
                cin >> colS[i][j][k];
            }
        }
    }

    ll res = LLONG_MAX;
    for (int i = 0; i < (1 << N); i++) {
        ll curr = 0;
        vec<bool> mask(N);
        for (int j = 0; j < N; j++) {
            mask[j] = (i >> j) & 1;
            if (mask[j]) curr += rowS[j];
        }

        for (int j = 0; j < M; j++) {
            curr += solve(mask, colS[j]);
        }

        res = min(res, curr);
    }

    cout << res;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2088 KiB
2Accepted0/03ms2144 KiB
3Accepted2/2149ms41248 KiB
4Accepted2/23ms2728 KiB
5Accepted3/34ms3232 KiB
6Accepted2/228ms8820 KiB
7Accepted2/2275ms66908 KiB
8Accepted2/2287ms67048 KiB
9Accepted2/2279ms67232 KiB
10Accepted2/2277ms67296 KiB
11Accepted2/2273ms66912 KiB
12Accepted2/2252ms61952 KiB
13Accepted2/2263ms61792 KiB
14Accepted2/275ms32808 KiB
15Accepted3/378ms32812 KiB
16Accepted3/3143ms42396 KiB
17Accepted2/2143ms42468 KiB
18Accepted3/3144ms42468 KiB
19Accepted2/2248ms61052 KiB
20Accepted2/2263ms64432 KiB
21Accepted2/2273ms66908 KiB
22Accepted2/2277ms67552 KiB
23Accepted2/2275ms67684 KiB
24Accepted2/2277ms67560 KiB
25Accepted2/2284ms67684 KiB