107892024-04-12 19:48:00MagyarKendeSZLGFestés (50 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2088 KiB
2Elfogadva0/03ms2144 KiB
3Elfogadva2/2149ms41248 KiB
4Elfogadva2/23ms2728 KiB
5Elfogadva3/34ms3232 KiB
6Elfogadva2/228ms8820 KiB
7Elfogadva2/2275ms66908 KiB
8Elfogadva2/2287ms67048 KiB
9Elfogadva2/2279ms67232 KiB
10Elfogadva2/2277ms67296 KiB
11Elfogadva2/2273ms66912 KiB
12Elfogadva2/2252ms61952 KiB
13Elfogadva2/2263ms61792 KiB
14Elfogadva2/275ms32808 KiB
15Elfogadva3/378ms32812 KiB
16Elfogadva3/3143ms42396 KiB
17Elfogadva2/2143ms42468 KiB
18Elfogadva3/3144ms42468 KiB
19Elfogadva2/2248ms61052 KiB
20Elfogadva2/2263ms64432 KiB
21Elfogadva2/2273ms66908 KiB
22Elfogadva2/2277ms67552 KiB
23Elfogadva2/2275ms67684 KiB
24Elfogadva2/2277ms67560 KiB
25Elfogadva2/2284ms67684 KiB