107902024-04-12 19:49:49MagyarKendeSZLGFestés (50 pont)cpp17Accepted 50/50289ms68504 KiB
// O(2^N(N + M(N^3)))
#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/03ms2100 KiB
2Accepted0/03ms2224 KiB
3Accepted2/2149ms41224 KiB
4Accepted2/23ms2704 KiB
5Accepted3/34ms3540 KiB
6Accepted2/228ms9160 KiB
7Accepted2/2275ms67076 KiB
8Accepted2/2287ms67312 KiB
9Accepted2/2287ms67512 KiB
10Accepted2/2277ms67640 KiB
11Accepted2/2275ms67112 KiB
12Accepted2/2252ms62084 KiB
13Accepted2/2261ms62092 KiB
14Accepted2/275ms33112 KiB
15Accepted3/378ms33104 KiB
16Accepted3/3143ms42532 KiB
17Accepted2/2148ms42756 KiB
18Accepted3/3143ms42972 KiB
19Accepted2/2248ms61416 KiB
20Accepted2/2263ms64924 KiB
21Accepted2/2273ms67260 KiB
22Accepted2/2277ms68172 KiB
23Accepted2/2289ms68420 KiB
24Accepted2/2289ms68504 KiB
25Accepted2/2286ms68372 KiB