107902024-04-12 19:49:49MagyarKendeSZLGFestés (50 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2100 KiB
2Elfogadva0/03ms2224 KiB
3Elfogadva2/2149ms41224 KiB
4Elfogadva2/23ms2704 KiB
5Elfogadva3/34ms3540 KiB
6Elfogadva2/228ms9160 KiB
7Elfogadva2/2275ms67076 KiB
8Elfogadva2/2287ms67312 KiB
9Elfogadva2/2287ms67512 KiB
10Elfogadva2/2277ms67640 KiB
11Elfogadva2/2275ms67112 KiB
12Elfogadva2/2252ms62084 KiB
13Elfogadva2/2261ms62092 KiB
14Elfogadva2/275ms33112 KiB
15Elfogadva3/378ms33104 KiB
16Elfogadva3/3143ms42532 KiB
17Elfogadva2/2148ms42756 KiB
18Elfogadva3/3143ms42972 KiB
19Elfogadva2/2248ms61416 KiB
20Elfogadva2/2263ms64924 KiB
21Elfogadva2/2273ms67260 KiB
22Elfogadva2/2277ms68172 KiB
23Elfogadva2/2289ms68420 KiB
24Elfogadva2/2289ms68504 KiB
25Elfogadva2/2286ms68372 KiB