84642024-01-16 21:19:57bovizdbFestés (50 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2084 KiB
2Elfogadva0/03ms2156 KiB
3Elfogadva2/2143ms42940 KiB
4Elfogadva2/23ms2648 KiB
5Elfogadva3/34ms3412 KiB
6Elfogadva2/226ms9440 KiB
7Elfogadva2/2261ms68792 KiB
8Elfogadva2/2244ms69016 KiB
9Elfogadva2/2250ms69084 KiB
10Elfogadva2/2244ms69064 KiB
11Elfogadva2/2241ms68676 KiB
12Elfogadva2/2219ms63604 KiB
13Elfogadva2/2230ms63556 KiB
14Elfogadva2/275ms34572 KiB
15Elfogadva3/379ms34768 KiB
16Elfogadva3/3136ms44200 KiB
17Elfogadva2/2136ms44204 KiB
18Elfogadva3/3136ms44460 KiB
19Elfogadva2/2217ms62976 KiB
20Elfogadva2/2231ms66276 KiB
21Elfogadva2/2243ms68796 KiB
22Elfogadva2/2244ms69752 KiB
23Elfogadva2/2244ms69600 KiB
24Elfogadva2/2241ms69604 KiB
25Elfogadva2/2259ms69600 KiB