205072026-01-07 13:24:52szabelrFestés (50 pont)cpp17Elfogadva 50/50270ms10224 KiB
// Festés_clean.c=pp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int ar[100001][5][5];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<int>sorar(n);
    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        sorar[i] = x;
    }
    //m,kezdet,veg
    for (int i = 1; i <= m; i++)
    {
        for (int y = 1; y <= n; y++)
        {
            for (int z = y; z <= n; z++)
            {
                int x; cin >> x;
                ar[i][y][z] = x;
            }
        }
    }
    long long best_sum = 1e18;
    for (int bitmask = 0; bitmask <= (1 << n)-1; bitmask++)
    {
        long long sum = 0;
        for (int j = 0; j <= n - 1; j++)
        {
            if ((bitmask & (1 << j)) != 0)
                sum += sorar[j];
        }
        for (int i = 1; i <= m; i++)
        {
            vector<long long>dp(n + 1, 1e18);
            dp[0] = 0;
            for (int y = 1; y <= n; y++)
            {
                if ((bitmask & (1 << (y - 1))) != 0)
                    dp[y] = dp[y-1];
                for (int z = 1; z <= n; z++)
                {
                    for (int q = z; q <= n; q++)
                    {
                        if(y>=z and y<=q)
                            dp[y] = min(dp[y], ar[i][z][q] + dp[z - 1]);
                     }
                 }
                
            }
            sum += dp[n];
        }
        best_sum = min(best_sum, sum);
    }
    cout << best_sum;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva2/2118ms10036 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva3/33ms316 KiB
6Elfogadva2/226ms1396 KiB
7Elfogadva2/2261ms10036 KiB
8Elfogadva2/2263ms9988 KiB
9Elfogadva2/2264ms10028 KiB
10Elfogadva2/2263ms10036 KiB
11Elfogadva2/2263ms10176 KiB
12Elfogadva2/2243ms9340 KiB
13Elfogadva2/2250ms9268 KiB
14Elfogadva2/254ms10036 KiB
15Elfogadva3/354ms10036 KiB
16Elfogadva3/3116ms10036 KiB
17Elfogadva2/2112ms10036 KiB
18Elfogadva3/3114ms10036 KiB
19Elfogadva2/2238ms9216 KiB
20Elfogadva2/2254ms9524 KiB
21Elfogadva2/2263ms9984 KiB
22Elfogadva2/2266ms10224 KiB
23Elfogadva2/2263ms10036 KiB
24Elfogadva2/2266ms10036 KiB
25Elfogadva2/2270ms10036 KiB