84642024-01-16 21:19:57bovizdbFestés (50 pont)cpp17Accepted 50/50261ms69752 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl "\n"
#define pll pair<ll, ll>
#define fs first
#define sc second
#define vll vector<ll>
#define v2d vector<vector<ll>>
#define vpll vector<pll>
#define qll queue<ll>
#define stll stack<ll>
#define sll set<ll>
#define mll map<ll, ll>

ll n, m;
vll r;
vector<v2d> c;
int b = 0b0000;


void solve()
{
    cin >> n >> m;
    r.resize(m);
    c.resize(m, v2d(n, vll(n)));
    for (ll i = 0; i < n; i++) cin >> r[i];
    for (ll i = 0; i < m; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            for (ll k = j; k < n; k++) cin >> c[i][j][k];
        }
    }
    ll out = LONG_MAX;
    for (ll i = 0; i < (1<<n); i++)
    {
        ll cost = 0;
        for (ll j = 0; j < n; j++) cost += bitset<4>(b)[j]*r[j];
        for (ll k = 0; k < m; k++)
        {
            vll dp(n);
            for (ll j = 0; j < n; j++)
            {
                if (j == 0)
                {
                    if (bitset<4>(b)[j] == 0) dp[0] = c[k][0][0];
                    continue;
                }
                dp[j] = c[k][0][j];
                ll mn = LONG_MAX;
                for (ll l = j; l >= 1; l--)
                {
                    mn = min(mn, dp[l-1]);
                    dp[j] = min(dp[j], c[k][l][j]+mn);
                }
                if (bitset<4>(b)[j] == 1) dp[j] = min(dp[j-1], dp[j]);
            }
            cost += dp[n-1];
        }
        out = min(out, cost);
        b += 1;
    }
    cout << out;
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2084 KiB
2Accepted0/03ms2156 KiB
3Accepted2/2143ms42940 KiB
4Accepted2/23ms2648 KiB
5Accepted3/34ms3412 KiB
6Accepted2/226ms9440 KiB
7Accepted2/2261ms68792 KiB
8Accepted2/2244ms69016 KiB
9Accepted2/2250ms69084 KiB
10Accepted2/2244ms69064 KiB
11Accepted2/2241ms68676 KiB
12Accepted2/2219ms63604 KiB
13Accepted2/2230ms63556 KiB
14Accepted2/275ms34572 KiB
15Accepted3/379ms34768 KiB
16Accepted3/3136ms44200 KiB
17Accepted2/2136ms44204 KiB
18Accepted3/3136ms44460 KiB
19Accepted2/2217ms62976 KiB
20Accepted2/2231ms66276 KiB
21Accepted2/2243ms68796 KiB
22Accepted2/2244ms69752 KiB
23Accepted2/2244ms69600 KiB
24Accepted2/2241ms69604 KiB
25Accepted2/2259ms69600 KiB